File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 1010from rdkit .Chem .rdmolops import GetFormalCharge
1111import gzip
1212from collections import Counter
13+ import json , glob , os
1314
1415def filter_pubchem (ms ):
1516 ms_filtered = []
@@ -37,8 +38,21 @@ def filter_pubchem(ms):
3738 ms_filtered .append (CalcMolFormula (m ))
3839 return ms_filtered
3940
41+ def write_json (ms , fname ):
42+ f = open (fname , 'w' )
43+ json .dump (ms , f )
44+ f .close ()
45+
46+
47+ sdf_path = 'F:/resources/isotope/pubchem/ftp.ncbi.nlm.nih.gov/pubchem/Compound/Monthly/2016-12-01/SDF/'
48+ sdfs = glob .glob (sdf_path + '*.sdf.gz' )
49+ for i , sdf in enumerate (sdfs ):
50+ print ( '{:2.4f}% {}' .format ((100 * float (i )/ len (sdfs )), sdf ))
51+ if not (os .path .exists (sdf [0 :- 6 ]+ 'json' )):
52+ sdf_gz = gzip .open (sdf )
53+ gzsuppl = Chem .ForwardSDMolSupplier (sdf_gz )
54+ ms = [Chem .AddHs (x ) for x in gzsuppl if x is not None ]
55+ ms_filtered = filter_pubchem (ms )
56+ write_json (ms_filtered , sdf [0 :- 6 ]+ 'json' )
57+
4058
41- inf = gzip .open ('F:/resources/isotope/pubchem/ftp.ncbi.nlm.nih.gov/pubchem/Compound/Monthly/2016-12-01/SDF/Compound_000000001_000025000.sdf.gz' )
42- gzsuppl = Chem .ForwardSDMolSupplier (inf )
43- ms = [Chem .AddHs (x ) for x in gzsuppl if x is not None ]
44- ms_filtered = filter_pubchem (ms )
You can’t perform that action at this time.
0 commit comments