A package to use several web services to find molecule structures, synonyms and CAS.
Project description
moleculeresolver
The moleculeresolver was born out of the need to annotate large datasets with accurate structural information fast and to crosscheck whether given metadata (name, SMILES) agrees with each other. It also allows to efficiently compare whether structures are available in two large datasets.
In short it's a Python module that allows you to retrieve molecular structures from multiple chemical databases, perform crosschecks to ensure data reliability, and standardize the best representation of molecules. It also provides functions for comparing molecules and sets of molecules based on specific configurations. This makes it a useful tool for researchers, chemists, or anyone working in computational chemistry / cheminformatics who needs to ensure they are working with the best available data for a molecule. The tool
Installation
The package is available on pypi:
pip install molecule-resolver
Features
- 🔍 Retrieve Molecular Structures: Fetch molecular structures from different chemical databases, including PubChem, Comptox, Chemo, and others.
- 🆔 Support for Different Identifier Types: Retrieve molecular structures using a variety of identifier types, including CAS numbers, SMILES, InChI, InChIkey and common names.
- ✅ Cross-check Capabilities: Use data from multiple sources to verify molecular structures and identify the best representation.
- 🔄 Molecule Comparison: Compare molecules or sets of molecules based on their structure, properties, and specified ⚙️ configurations.
- ⚙️ Standardization: Standardize molecular structures, including handling isomers, tautomers, and isotopes.
- 💾 Caching Mechanism: Use local caching to store molecules and reduce the number of repeated requests to external services, improving performance and reducing latency.
🚀 Usage
Initialization
To use Molecule Resolver, first import and initialize the MoleculeResolver
class. it is supposed to be used as a context manager:
from moleculeresolver import MoleculeResolver
with MoleculeResolver(available_service_API_keys={"chemeo": "YOUR_API_KEY"}) as mr:
...
Retrieve and Compare Molecules by Name and CAS
Retrieve a molecule using both its common name and CAS number, then compare the two to ensure they represent the same structure:
from rdkit import Chem
from moleculeresolver import MoleculeResolver
with MoleculeResolver(available_service_API_keys={"chemeo": "YOUR_API_KEY"}) as mr:
molecule_name = mr.find_single_molecule(["aspirin"], ["name"])
molecule_cas = mr.find_single_molecule(["50-78-2"], ["cas"])
are_same = mr.are_equal(Chem.MolFromSmiles(molecule_name.SMILES),
Chem.MolFromSmiles(molecule_cas.SMILES))
print(f"Are the molecules the same? {are_same}")
Parallelized Molecule Retrieval and Saving to JSON
Use the parallelized version to retrieve multiple molecules. If a large number of molecules is searched, moleculeresolver will try to use batch download capabilities whenever the database supports this.
import json
from moleculeresolver import MoleculeResolver
molecule_names = ["aspirin", "propanol", "ibuprofen", "non-exixtent-name"]
not_found_molecules = []
molecules_dicts = {}
with MoleculeResolver(available_service_API_keys={"chemeo": "YOUR_API_KEY"}) as mr:
molecules = mr.find_multiple_molecules_parallelized(molecule_names, [["name"]] * len(molecule_names))
for name, molecule in zip(molecule_names, molecules):
if molecule:
molecules_dicts[name] = molecule.to_dict(found_molecules='remove')
else:
not_found_molecules.append(name)
with open("molecules.json", "w") as json_file:
json.dump(molecules_dicts, json_file, indent=4)
print(f"Molecules not found: {not_found_molecules}")
⚙️ Configuration
The MoleculeResolver
class allows users to configure various options like:
- API Keys: Set API keys for accessing different molecular databases. Currently only chemeo needs one.
- Standardization Options: Choose how to handle molecular standardization (e.g., normalizing functional groups, disconnecting metals, handling isomers, etc.).
- Differentiation Settings: Options for distinguishing between isomers, tautomers, and isotopes.
🤝 Contributing
Contributions are welcome! If you have suggestions for improving the Molecule Resolver or want to add new features, feel free to submit an issue or a pull request on GitHub.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file molecule_resolver-0.2.2.tar.gz
.
File metadata
- Download URL: molecule_resolver-0.2.2.tar.gz
- Upload date:
- Size: 76.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c62e0cc36c94852e0c38175eb1b816a5ab0268a8adaa7143ce370abf3dc6a60 |
|
MD5 | a135b953c46ee705c24ced26fda3a3ee |
|
BLAKE2b-256 | 0060f5e6996d5dffc89ca62b13a3606c8c13e494fde0ab821162ec669b87f7e0 |
Provenance
The following attestation bundles were made for molecule_resolver-0.2.2.tar.gz
:
Publisher:
ci.yml
on MoleculeResolver/molecule-resolver
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
molecule_resolver-0.2.2.tar.gz
- Subject digest:
8c62e0cc36c94852e0c38175eb1b816a5ab0268a8adaa7143ce370abf3dc6a60
- Sigstore transparency entry: 146290148
- Sigstore integration time:
- Predicate type:
File details
Details for the file molecule_resolver-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: molecule_resolver-0.2.2-py3-none-any.whl
- Upload date:
- Size: 78.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55ba4703c79905213353fbd261ca00cc468436fc4651998e75bfe11af31a6350 |
|
MD5 | 6db3601ff2b35866f5ad4764124113c3 |
|
BLAKE2b-256 | a5585ed800c153d81a75e4463ab0647d1e23a8759ec522126e97ed3114d18c2f |
Provenance
The following attestation bundles were made for molecule_resolver-0.2.2-py3-none-any.whl
:
Publisher:
ci.yml
on MoleculeResolver/molecule-resolver
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
molecule_resolver-0.2.2-py3-none-any.whl
- Subject digest:
55ba4703c79905213353fbd261ca00cc468436fc4651998e75bfe11af31a6350
- Sigstore transparency entry: 146290150
- Sigstore integration time:
- Predicate type: