PubChemPy examples

Table of Contents

2. Getting Started

Retrieving a Compound

Retrieving information about a specific Compound in the PubChem database is simple.

Begin by importing PubChemPy:


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]:
Compound(5090)

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)


C17H14O4S

In [7]:
print(c.molecular_weight)


314.35566

In [9]:
print(c.isomeric_smiles)


CS(=O)(=O)C1=CC=C(C=C1)C2=C(C(=O)OC2)C3=CC=CC=C3

In [10]:
print(c.xlogp)


2.3

In [11]:
print(c.iupac_name)


3-(4-methylsulfonylphenyl)-4-phenyl-2H-furan-5-one

In [12]:
print(c.synonyms)


[u'rofecoxib', u'Vioxx', u'Ceoxx', u'162011-90-7', u'MK 966', u'MK-966', u'4-[4-(methylsulfonyl)phenyl]-3-phenylfuran-2(5H)-one', u'MK-0966', u'Vioxx (trademark)', u'MK 0966', u'CCRIS 8967', u'CHEBI:8887', u'Vioxx (TN)', u'HSDB 7262', u'Spectrum_000119', u'SpecPlus_000669', u'Spectrum2_000446', u'Spectrum3_001153', u'Spectrum4_000631', u'Spectrum5_001598', u'UNII-0QTW8Z7MCR', u'MK 996', u'MK0966', u'CHEMBL122', u'AC1L1JL6', u'KS-1107', u'3-(4-methylsulfonylphenyl)-4-phenyl-2H-furan-5-one', u'4-(4-methylsulfonylphenyl)-3-phenyl-5H-furan-2-one', u'NCGC00095118-01', u'BSPBio_002705', u'KBioGR_001242', u'KBioGR_002345', u'KBioSS_000559', u'KBioSS_002348', u'Rofecoxib (JAN/USAN/INN)', u'BIDD:GT0399', u'Bio-0094', u'DivK1c_006765', u'4-[4-(methylsulfonyl)phenyl]-3-phenyl-2(5H)-furanone', u'SPBio_000492', u'SPECTRUM1504235', u'MLS000759440', u'MLS001165770', u'MLS001195623', u'MLS001424113', u'Jsp003237', u'C17H14O4S', u'KBio1_001709', u'KBio2_000559', u'KBio2_002345', u'KBio2_003127', u'KBio2_004913', u'KBio2_005695', u'KBio2_007481', u'KBio3_002205', u'KBio3_002825', u'cMAP_000024', u'MolPort-000-883-878', u'MolPort-006-817-786', u'HMS1922H11', u'HMS2051G16', u'HMS2089H20', u'HMS2093E04', u'NSC720256', u'STK635144', u'ZINC00007455', u'AKOS000280931', u'4-(4-(Methylsulfonyl)phenyl)-3-phenyl-2(5H)-furanone', u'4-(p-(Methylsulfonyl)phenyl)-3-phenyl-2(5H)-furanone', u'DB00533', u'MK 0996', u'2(5H)-Furanone, 4-(4-(methylsulfonyl)phenyl)-3-phenyl-', u'3-Phenyl-4-(4-(methylsulfonyl)phenyl))-2(5H)-furanone', u'NCGC00095118-02', u'NCGC00095118-03', u'NCGC00095118-04', u'AC-13144', u'CPD000466331', u'LS-70511', u'NCI60_041175', u'SAM001246617', u'SMR000466331', u'FT-0081390', u'C07590', u'D00568', u'L000912', u'186912-82-3', u'BRD-K21733600-001-02-6', u'I01-1042', u'3-phenyl-4-[4-(methylsulfonyl)phenyl]-2(5H)-furanone', u'4-(4-(Methylsulfonyl)phenyl)-3-phenylfuran-2(5H)-one', u'refecoxib', u'2(5H)-Furanone, 4-[4-(methyl-sulfonyl)phenyl]-3-phenyl-', u'Vioxx Dolor', u'MSD brand of rofecoxib', u'Merck brand of rofecoxib', u'2(5H)-Furanone, 4-[4-(methylsulfonyl)phenyl]-3-phenyl-', u'Merck Frosst brand of rofecoxib', u'CID5090', u'Rofecoxib (Vioxx)', u'Rofecoxib [USAN]', u'Cahill May Roberts brand of rofecoxib', u'Merck Sharp & Dhome brand of rofecoxib', u'PubChem15028', u'SureCN3050', u'DSSTox_CID_3567', u'AGN-PC-00E0TK', u'DSSTox_RID_77084', u'C116926', u'DSSTox_GSID_23567', u'Rofecoxib [USAN:INN:BAN]', u'GTPL2893', u'HMS2232G21', u'HMS3371P11', u'HMS3393G16', u'MK966', u'Pharmakon1600-01504235', u'Tox21_111430', u'ANW-71936', u'CCG-40253', u'DAP001338', u'NSC758705', u'AB07701', u'BD41342', u'CS-0997', u'MCULE-4806636118', u'NC00132', u'NSC-720256', u'NSC-758705', u'NCGC00095118-05', u'AK-60971', u'HY-17372', u'CAS-162011-90-7', u'FT-0631192', u'K-5064', u'AB00052090-06', u'AB00052090-08', u'A810324', u'3B2-0954', u'Rofecoxib|162011-90-7|Vioxx|MK966|MK-966', u'4-(4-METHANESULFONYL-PHENYL)-3-PHENYL-5H-FURAN-2-ONE', u'4-(4-methanesulfonylphenyl)-3-phenyl-2,5-dihydrofuran-2-one']

Searching

What if you don’t know the PubChem CID of the Compound you want? Just use the get_compounds() function:


In [13]:
results = pcp.get_compounds('Glucose', 'name')
results


Out[13]:
[Compound(5793), Compound(79025), Compound(64689), Compound(206)]

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


C([C@@H]1[C@H]([C@@H]([C@H](C(O1)O)O)O)O)O
C([C@@H]1[C@H]([C@@H]([C@H]([C@H](O1)O)O)O)O)O
C([C@@H]1[C@H]([C@@H]([C@H]([C@@H](O1)O)O)O)O)O
C(C1C(C(C(C(O1)O)O)O)O)O

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]:
[Compound(1318)]

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