Utilities

Utilities module

source

canonicalize

 canonicalize (smi:str, clear_stereo:bool=False)

This function returns the canonicalised smiles representation and has the option to clear stereochemistry

Type Default Details
smi str input molecule
clear_stereo bool False if True, clears stereochemistry of the molecule (remove the @@)
Returns str canonicalised molecule
canonicalize('C(CC)N(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O')
'CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O'

Canonicalizing an already canonicalized molecule

canonicalize('CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O')
'CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O'

Unit Tests

test_eq(canonicalize('C(CC)N(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O'), canonicalize('CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O'))
test_fail(canonicalize('CN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O'), 'CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O')

source

mol_from_smiles

 mol_from_smiles (smi:str)

This function converts a SMILES string to a molecule.

Type Details
smi str Input molecule in SMILES.
Returns Mol Output molecule.
mol_from_smiles('CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O')

mol_from_smiles('CSc1cccc2sc(N3CCN(C(=O)c4ccn(C(C)C)n4)CC3)nc12')


source

mol_to_smiles

 mol_to_smiles (mol:rdkit.Chem.rdchem.Mol, rootedAtAtom:int=None)

This function converts a molecule to a SMILES string.

Type Default Details
mol Mol molecule to convert into SMILES string
rootedAtAtom int None SMILES string rooted at the input atom
Returns str canonicalized SMILES string
mol = mol_from_smiles('CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O')
mol

mol_to_smiles(mol)
'CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O'
mol_to_smiles(mol, rootedAtAtom=3)
'N(CCC)(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O'

Unit Tests

mol = mol_from_smiles('CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O')
mol_2 = mol_from_smiles('C(CC)N(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O')
test_eq(mol_to_smiles(mol), 'CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O')
test_eq(mol_to_smiles(mol, rootedAtAtom=3), 'N(CCC)(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O')
test_eq(mol_to_smiles(mol), mol_to_smiles(mol_2))

source

root_smiles

 root_smiles (smi:str, rootedAtAtom:int)

Root molecule in smiles format at a defined atom

Type Details
smi str Input molecule in SMILES
rootedAtAtom int SMILES string rooted at the input atom
Returns str
root_smiles('CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O', rootedAtAtom=3)
'N(CCC)(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O'
root_smiles('CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O', rootedAtAtom=0)
'CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O'

Unit Tests

test_eq(root_smiles('CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O', rootedAtAtom=0), 'CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O')
test_eq(root_smiles('CCCN(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O', rootedAtAtom=3), 'N(CCC)(CCc1cccc(-c2ccccc2)c1)C(=O)C1OC(C(=O)O)=CC(N)C1NC(C)=O')