In [1]:
import pubchempy as pcp
Let’s get the Compound with CID 5090:
In [3]:
c = pcp.Compound.from_cid(5090)
c
Out[3]:
Now we have a Compound
object called c
. We can get all the information we need from this object:
In [8]:
print(c.molecular_formula)
In [7]:
print(c.molecular_weight)
In [9]:
print(c.isomeric_smiles)
In [10]:
print(c.xlogp)
In [11]:
print(c.iupac_name)
In [12]:
print(c.synonyms)
In [13]:
results = pcp.get_compounds('Glucose', 'name')
results
Out[13]:
The first argument is the identifier, and the second argument is the identifier type, which must be one of name, smiles, sdf, inchi, inchikey or formula. It looks like there are 4 compounds in the PubChem Database that have the name Glucose associated with them. Let’s take a look at them in more detail:
In [14]:
for compound in results:
print compound.isomeric_smiles
It looks like they all have different stereochemistry information.
Retrieving the record for a SMILES string is just as easy:
In [15]:
pcp.get_compounds('C1=CC2=C(C3=C(C=CC=N3)C=C2)N=C1', 'smiles')
Out[15]:
It's worth being aware that line notation inputs like SMILES and InChI can return automatically generated records that aren’t actually present in PubChem, and therefore have no CID and are missing many properties that are too complicated to calculate on the fly.
Previous: Introduction