-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a97a050
commit b01f90e
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Read all the molecules in a database.""" # noqa: INP001 | ||
|
||
import argparse | ||
from pathlib import Path | ||
|
||
import atomlite | ||
|
||
|
||
def main() -> None: | ||
"""Run the example.""" | ||
args = _parse_args() | ||
db = atomlite.Database(args.database) | ||
for entry in db.get_entries(): | ||
molecule = atomlite.json_to_rdkit(entry.molecule) # noqa: F841 | ||
# do something with molecule | ||
|
||
|
||
def _parse_args() -> argparse.Namespace: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"database", | ||
help="Path to the atomlite file.", | ||
type=Path, | ||
) | ||
return parser.parse_args() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Write the ChEMBL database to an AtomLite file.""" # noqa: INP001 | ||
|
||
import argparse | ||
from pathlib import Path | ||
|
||
import atomlite | ||
import rdkit.Chem as rdkit # noqa: N813 | ||
|
||
|
||
def main() -> None: | ||
"""Run the example.""" | ||
args = _parse_args() | ||
chembl = rdkit.SDMolSupplier(args.chembl) | ||
db = atomlite.Database(args.output) | ||
for i, mol in enumerate(chembl): | ||
db.add_entries( | ||
atomlite.Entry.from_rdkit( | ||
key=str(i), | ||
molecule=mol, | ||
properties=mol.GetPropsAsDict(), | ||
), | ||
commit=False, | ||
) | ||
db.connection.commit() | ||
|
||
|
||
def _parse_args() -> argparse.Namespace: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"chembl", | ||
help="Path to the ChEMBL sdf database file.", | ||
type=Path, | ||
) | ||
parser.add_argument( | ||
"output", | ||
help="Path to the output atomlite file.", | ||
type=Path, | ||
) | ||
return parser.parse_args() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |