Created
December 16, 2016 11:03
-
-
Save justheuristic/fc86974d2c4d8cb86bb537f4235b53ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #http://chemspipy.readthedocs.io/en/latest/guide/install.html | |
| import chemspipy as chpy | |
| token = "<your token from http://chemspipy.readthedocs.io/en/latest/guide/intro.html#securitytoken>" | |
| cs = chpy.ChemSpider(token) | |
| n_samples = 10**5 #amount of molecules to save | |
| import numpy as np | |
| #seed random compound ids (~90% valid) | |
| compound_ids = np.random.choice(58191596,size=n_samples,replace=False) | |
| #you may need to avoid duplicates when downloading additional data | |
| #the compound ids are avaliable through data['csid'] | |
| data = [] | |
| for i,csid in enumerate(compound_ids): | |
| try: | |
| info = cs.get_extended_compound_info(csid) | |
| info['csid']=csid | |
| data.append(info) | |
| except chpy.errors.ChemSpiPyError: pass | |
| if i%100==0: | |
| print i,'/',len(compound_ids) | |
| import pandas as pd | |
| df = pd.DataFrame(data) | |
| df.to_csv("./data.tsv",sep='\t') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment