Skip to content

Commit

Permalink
Add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasturcani committed Apr 24, 2024
1 parent a97a050 commit b01f90e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
29 changes: 29 additions & 0 deletions examples/read_database.py
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()
43 changes: 43 additions & 0 deletions examples/write_chembl.py
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()

0 comments on commit b01f90e

Please sign in to comment.