Nov-23-2018, 03:15 PM
Thank you Larz60+ and Gribouillis for your suggestions. Now the program writes in the original file although it is appending everything to the bottom of the file and I would like to append a number in each file.
About what Gribouillis suggests, the output I get in my screen is:
COC1=C(=C)......
63.95
COC1=CC.....
72.74
C[C@H]1CO...
75.01
CC1CN...
74.57
And want to append in the original file is 63.95 to the first line, 72.72 to the second line and so on, separated from the smiles with a comma, like the first two entries in each file, like this:
Verapamil,sub,COC1=C(OC)C=C(CCN©CCCC(C#N)(C©C)C2=CC(OC)=C(OC)C=C2)C=C1,63.95
Norverapamil,sub,COC1=CC=C(CCNCCCC(C#N)(C©C)C2=CC(OC)=C(OC)C=C2)C=C1OC,72.74
levofloxacin,sub,C[C@H]1COC2=C3N1C=C(C(O)=O)C(=O)C3=CC(F)=C2N1CCN©CC1,75.01
Below I show you what I have now (but it is appending all the orders to the bottom of the file):
Sorry that I can't explain better in English and thank you both very much.
About what Gribouillis suggests, the output I get in my screen is:
COC1=C(=C)......
63.95
COC1=CC.....
72.74
C[C@H]1CO...
75.01
CC1CN...
74.57
And want to append in the original file is 63.95 to the first line, 72.72 to the second line and so on, separated from the smiles with a comma, like the first two entries in each file, like this:
Verapamil,sub,COC1=C(OC)C=C(CCN©CCCC(C#N)(C©C)C2=CC(OC)=C(OC)C=C2)C=C1,63.95
Norverapamil,sub,COC1=CC=C(CCNCCCC(C#N)(C©C)C2=CC(OC)=C(OC)C=C2)C=C1OC,72.74
levofloxacin,sub,C[C@H]1COC2=C3N1C=C(C(O)=O)C(=O)C3=CC(F)=C2N1CCN©CC1,75.01
Below I show you what I have now (but it is appending all the orders to the bottom of the file):
Sorry that I can't explain better in English and thank you both very much.
import os import subprocess path_input = '/home/c.blanes/pgp/training.txt' obabel = '/usr/bin/obabel ' with open(path_input, 'r') as f_in, open(path_input, 'a') as f_out: for line in f_in.readlines(): smiles = line.split(',')[2].strip('\n') print(smiles) launch = obabel + '-:\'%s\' -otxt --append TPSA'%(smiles) subprocess.call(launch, shell=True) f_out.write(launch)