Getting Started
This is a small introduction to help you get started with Chemaxon Python API. For a thorough documentation, go to the API Reference. A more detailed list of examples can be found in the python examples project.
Molecule import
You can easily import molecules from various formats. You can either specify the format yourself,
or if you do not specify any format, the function will recognize the format automatically.
| from chemaxon import import_mol
mol = import_mol("CC(=O)OC1=CC=CC=C1C(O)=O")
mol2 = import_mol("CC(=O)OC1=CC=CC=C1C(O)=O", "smiles")
|
The import_mol function returns a chemaxon.molecule.Molecule object on success.
Bulk import from file:
| from chemaxon import MolImporter
with MolImporter("my_molecules.sdf") as mol_iterator :
for mol in mol_iterator :
print(export_mol(mol, "smiles:u"))
|
Molecule display
The molecule can be exported to an svg file string:
| from chemaxon import import_mol
mol = import_mol("CC(=O)OC1=CC=CC=C1C(O)=O")
svg = mol._repr_svg_()
|

Calculations
Once you have a molecule, you can calculate various properties of it.
| from chemaxon import logp, LogpMethod
result = logp(mol, method=LogpMethod.CHEMAXON, consider_tautomerization=True)
|
This function returns a chemaxon.calculations.logp.LogPResult object, which contains the calculated logP value,
and the logP values of the individual atoms.
You can also calculate logp using the default parameter values:
| from chemaxon import logp
result = logp(mol)
|
Fingerprint calculations
Chemaxon has a number of functions that you can use to generate fingerprints.
| from chemaxon import cfp, ecfp
cfp = cfp(mol)
ecfp = ecfp(mol, 4, 1024)
|
These functions return chemaxon.fingerprints.fingerprint.Fingerprint objects. You can get the fingerprints
in bytes or in binary string format.
| ecfp.to_bytes()
ecfp.to_binary_string()
|
You can also calculate pharmacophore fingerprints:
| from chemaxon import pharmacophore_fp
pf = pharmacophore_fp(mol)
|
This method returns a FloatVectorFingerprint, which contains a float array.
You can also calculate Tanimoto Dissimilarity for the fingerprints:
| from chemaxon import tanimoto, ecfp, pharmacophore_fp, float_vector_tanimoto
ecfp1 = ecfp(mol, 4, 1024)
ecfp2 = ecfp(mol2, 4, 1024)
result1 = tanimoto(ecfp1, ecfp2)
pf1 = pharmacophore_fp(mol)
pf2 = pharmacophore_fp(mol2)
result2 = float_vector_tanimoto(pf1, pf2)
|
Structure standardization
Standardization in python works similar to our other tools.
See more information about standardization in general: Standardizer Introduction
and the list of available standardizer actions.
Standardizer can be configured via action strings:
| from chemaxon import import_mol, Standardizer
standardizer = Standardizer("dearomatize..removeexplicith:lonely")
mol = import_mol("[H]c1c([H])c([H])c([H])c([H])c1[H].[H]")
standard_mol = standardizer.standardize(mol)
|
Or via xml configuration:
| from chemaxon import import_mol, Standardizer
configFile = "path/to/my_config.xml"
with open(configFile) as config:
standardizer = Standardizer(config)
mol = import_mol("[H].[H]C1=C([H])C([H])=C([H])C([H])=C1[H]")
standard_mol = standardizer.standardize(mol)
|
Structure checker
For the concept of Structure Checker in general see Structure Checker User's Guide.
Built-in checkers and fixers are available from Chemaxon Python API, custom implementations are not supported yet.
Structure fixer keeps the input molecule unchanged and returns an object containing the result molecule and a flag indicating if the fix was successful.
The following example shows the configuration and usage of structure checker via action strings:
| from chemaxon import import_mol, StructureChecker
mol = import_mol('[NH3+]C1=CC(O)=CC=C1.O')
checker = StructureChecker('solvent->removeatom..moleculecharge->neutralize')
check_result = checker.check(mol)
for r in check_result.results:
print('Checker name:', r.checker_name)
fix_result = checker.fix(mol)
print("Fix was" + ("" if fix_result.is_fix_successful else "n't") + " successful.")
fixed_molecule = fix_result.fixed_mol
|
Action strings can be specified as list as well:
| ...
checker = StructureChecker(["solvent->removeatom","moleculecharge->neutralize"])
...
|
Using xml files structure checker creation changes as follows:
| ...
configFile = "path/to/my_config.xml"
with open(configFile) as config:
checker = StuctureChecker(config)
...
|
Exception-handling
| from chemaxon import Molecule, LogpMethod, import_mol, logp
try:
# for illustrating exeption raising, a non-importable molecule is used
mol = Molecule("non-importable", None)
logp(mol, LogpMethod.CHEMAXON, -12, -34, consider_tautomerization=True, ph=15)
except RuntimeError as e:
# custom error handler code
|