from chemspipy import ChemSpider

"""
Explanation: ChemSpiPy: Getting Started
Before we start:

Make sure you have installed ChemSpiPy.
Obtain a security token from the ChemSpider web site.

First Steps
Start by importing ChemSpider:
End of explanation
"""


# Tip: Store your security token as an environment variable to reduce the chance of accidentally sharing it
import os
mytoken = os.environ['CHEMSPIDER_SECURITY_TOKEN']

cs = ChemSpider(security_token=mytoken)

"""
Explanation: Then connect to ChemSpider by creating a ChemSpider instance using your security token:
End of explanation
"""


comp = cs.get_compound(2157)
comp

"""
Explanation: All your interaction with the ChemSpider database should now happen through this ChemSpider object, cs.
Retrieve a Compound
Retrieving information about a specific Compound in the ChemSpider database is simple.
Let’s get the Compound with ChemSpider ID 2157:
End of explanation
"""


print(comp.molecular_formula)
print(comp.molecular_weight)
print(comp.smiles)
print(comp.common_name)

"""
Explanation: Now we have a Compound object called comp. We can get various identifiers and calculated properties from this object:
End of explanation
"""


for result in cs.search('glucose'):
    print(result)

"""
Explanation: Search for a name
What if you don’t know the ChemSpider ID of the Compound you want? Instead use the search method:
End of explanation
"""


