Entering edit mode
9.5 years ago
alsalisbeth
▴
10
Hello,
I am trying to convert my files (several thousands) in one format to another format using pymol script. I would like them to be saved in the same folder, i.e.: ~/myFolder/file.pdb
--------> ~/myFolder/file.mol
My script:
import os
from pymol import cmd
myDir = '/folderWithFilesToConvert'
print(myDir)
for filename in os.listdir(myDir):
filename = os.path.splitext(filename)[0]
print('New file name is', filename)
if '_' in filename:
print filename
cmd.h_add
#till the line below everything works fine
cmd.save(filename.mol)
What is wrong? Console output:
​AttributeError: 'str' object has no attribute 'mol'
Thanks
Some update. I modified code like that (thanks to @Felix_Sim):
import os
from pymol import cmd
myDir = '/Users/AnnaLisa/Desktop/FRAG'
print(myDir)
for filename in os.listdir(myDir):
filename = os.path.splitext(filename)[0]
print('New file name is', filename)
if '_' in filename:
print filename
cmd.h_add
cmd.save(filename + '.mol')
If I convert file via command line, I get (inside the file) ​
untitled
ChemPy 3D 0
0 0 0 0 1 0 0 0 0 0999 V2000
M END
If I convert file manually in PyMol via GUI (inside the file):
017
ChemPy 3D 0
75 78 0 0 1 0 0 0 0 0999 V2000
21.0910 28.7350 14.0670 N 0 0 0 0 0 0 0 0 0 0 0 0
20.5400 27.5660 14.5190 C 0 0 0 0 0 0 0 0 0 0 0 0
19.1880 27.3330 14.2100 C 0 0 0 0 0 0 0 0 0 0 0 0
18.6260 26.1600 14.6750 C 0 0 0 0 0 0 0 0 0 0 0 0
19.3840 25.2160 15.3450 C 0 0 0 0 0 0 0 0 0 0 0 0
20.7110 25.4230 15.7210 C 0 0 0 0 0 0 0 0 0 0 0 0
21.2630 26.6460 15.2920 C 0 0 0 0 0 0 0 0 0 0 0 0
18.4500 23.7990 15.9930 S 0 0 0 0 0 0 0 0 0 0 0 0
17.2570 23.4660 15.0690 O 0 0 0 0 0 0 0 0 0 0 0 0
19.4810 22.6380 16.2400 O 0 0 0 0 0 0 0 0 0 0 0 0
17.7940 24.1570 17.5840 N 0 0 0 0 0 0 0 0 0 0 0 0
18.7830 24.4260 18.6320 C 0 0 0 0 0 0 0 0 0 0 0 0
18.4000 23.8560 20.0060 C 0 0 0 0 0 0 0 0 0 0 0 0
18.3680 22.3520 19.8930 C 0 0 0 0 0 0 0 0 0 0 0 0
19.5030 24.3350 20.9200 C 0 0 0 0 0 0 0 0 0 0 0 0
16.5050 24.8940 17.5640 C 0 0 0 0 0 0 0 0 0 0 0 0
15.3940 23.9640 18.1580 C 0 0 0 0 0 0 0 0 0 0 0 0
14.2320 24.7640 18.4090 O 0 0 0 0 0 0 0 0 0 0 0 0
15.0130 22.8280 17.1770 C 0 0 0 0 0 0 0 0 0 0 0 0
14.1320 21.9410 17.8870 N 0 0 0 0 0 0 0 0 0 0 0 0
14.4880 20.6750 18.2230 C 0 0 0 0 0 0 0 0 0 0 0 0
15.5870 20.0860 17.9550 O 0 0 0 0 0 0 0 0 0 0 0 0
13.4210 20.0660 18.9520 O 0 0 0 0 0 0 0 0 0 0 0 0
13.5050 18.6020 19.1020 C 0 0 0 0 0 0 0 0 0 0 0 0
12.8390 18.3510 20.4850 C 0 0 0 0 0 0 0 0 0 0 0 0
11.4120 18.4700 20.2840 O 0 0 0 0 0 0 0 0 0 0 0 0
11.2200 17.9780 18.9680 C 0 0 0 0 0 0 0 0 0 0 0 0
10.2970 18.8060 18.2910 O 0 0 0 0 0 0 0 0 0 0 0 0
11.0420 19.4440 17.2410 C 0 0 0 0 0 0 0 0 0 0 0 0
12.1310 18.4320 16.8180 C 0 0 0 0 0 0 0 0 0 0 0 0
12.4700 17.8870 18.2130 C 0 0 0 0 0 0 0 0 0 0 0 0
14.2940 23.2850 15.8960 C 0 0 0 0 0 0 0 0 0 0 0 0
12.5490 21.7500 14.8810 C 0 0 0 0 0 0 0 0 0 0 0 0
12.1480 20.6610 14.0690 C 0 0 0 0 0 0 0 0 0 0 0 0
13.1190 19.9330 13.3910 C 0 0 0 0 0 0 0 0 0 0 0 0
14.4710 20.2400 13.5170 C 0 0 0 0 0 0 0 0 0 0 0 0
14.8600 21.3260 14.3140 C 0 0 0 0 0 0 0 0 0 0 0 0
13.9020 22.1140 14.9680 C 0 0 0 0 0 0 0 0 0 0 0 0
18.6130 28.0420 13.6330 H 0 0 0 0 0 0 0 0 0 0 0 0
17.5740 25.9760 14.5120 H 0 0 0 0 0 0 0 0 0 0 0 0
21.2720 24.7020 16.2970 H 0 0 0 0 0 0 0 0 0 0 0 0
22.2800 26.8840 15.5680 H 0 0 0 0 0 0 0 0 0 0 0 0
22.0490 28.7830 14.3490 H 0 0 0 0 0 0 0 0 0 0 0 0
21.0350 28.7660 13.0690 H 0 0 0 0 0 0 0 0 0 0 0 0
17.4150 24.1730 20.3800 H 0 0 0 0 0 0 0 0 0 0 0 0
15.7770 23.5030 19.0810 H 0 0 0 0 0 0 0 0 0 0 0 0
13.5430 24.2180 18.7710 H 0 0 0 0 0 0 0 0 0 0 0 0
15.9530 22.3620 16.8450 H 0 0 0 0 0 0 0 0 0 0 0 0
13.2230 22.2690 18.1430 H 0 0 0 0 0 0 0 0 0 0 0 0
14.5380 18.2740 18.9140 H 0 0 0 0 0 0 0 0 0 0 0 0
10.8250 16.9550 19.0470 H 0 0 0 0 0 0 0 0 0 0 0 0
12.9200 16.9040 18.0070 H 0 0 0 0 0 0 0 0 0 0 0 0
11.8080 22.3050 15.4380 H 0 0 0 0 0 0 0 0 0 0 0 0
11.1040 20.4000 13.9780 H 0 0 0 0 0 0 0 0 0 0 0 0
12.8190 19.1140 12.7540 H 0 0 0 0 0 0 0 0 0 0 0 0
15.2140 19.6470 13.0050 H 0 0 0 0 0 0 0 0 0 0 0 0
15.9090 21.5580 14.4250 H 0 0 0 0 0 0 0 0 0 0 0 0
19.7360 23.9690 18.3270 H 0 0 0 0 0 0 0 0 0 0 0 0
18.8860 25.5170 18.7320 H 0 0 0 0 0 0 0 0 0 0 0 0
18.0960 21.9160 20.8660 H 0 0 0 0 0 0 0 0 0 0 0 0
17.6240 22.0570 19.1380 H 0 0 0 0 0 0 0 0 0 0 0 0
19.3610 21.9860 19.5930 H 0 0 0 0 0 0 0 0 0 0 0 0
19.3160 23.9730 21.9420 H 0 0 0 0 0 0 0 0 0 0 0 0
20.4690 23.9460 20.5640 H 0 0 0 0 0 0 0 0 0 0 0 0
19.5280 25.4350 20.9190 H 0 0 0 0 0 0 0 0 0 0 0 0
16.5890 25.8090 18.1690 H 0 0 0 0 0 0 0 0 0 0 0 0
16.2480 25.1680 16.5300 H 0 0 0 0 0 0 0 0 0 0 0 0
13.0920 17.3470 20.8570 H 0 0 0 0 0 0 0 0 0 0 0 0
13.1870 19.0930 21.2190 H 0 0 0 0 0 0 0 0 0 0 0 0
10.3860 19.6860 16.3920 H 0 0 0 0 0 0 0 0 0 0 0 0
11.4990 20.3780 17.6010 H 0 0 0 0 0 0 0 0 0 0 0 0
11.7670 17.6610 16.1230 H 0 0 0 0 0 0 0 0 0 0 0 0
12.9880 18.8970 16.3090 H 0 0 0 0 0 0 0 0 0 0 0 0
13.3760 23.8160 16.1870 H 0 0 0 0 0 0 0 0 0 0 0 0
14.9690 23.9530 15.3410 H 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0 0 0 0
1 43 1 0 0 0 0
1 44 1 0 0 0 0
2 3 2 0 0 0 0
2 7 1 0 0 0 0
3 4 1 0 0 0 0
3 39 1 0 0 0 0
4 5 2 0 0 0 0
4 40 1 0 0 0 0
5 6 1 0 0 0 0
5 8 1 0 0 0 0
6 7 2 0 0 0 0
6 41 1 0 0 0 0
7 42 1 0 0 0 0
8 9 2 0 0 0 0
8 10 2 0 0 0 0
8 11 1 0 0 0 0
11 12 1 0 0 0 0
11 16 1 0 0 0 0
12 13 1 0 0 0 0
12 58 1 0 0 0 0
12 59 1 0 0 0 0
13 14 1 0 0 0 0
13 15 1 0 0 0 0
13 45 1 0 0 0 0
14 60 1 0 0 0 0
14 61 1 0 0 0 0
14 62 1 0 0 0 0
15 63 1 0 0 0 0
15 64 1 0 0 0 0
15 65 1 0 0 0 0
16 17 1 0 0 0 0
16 66 1 0 0 0 0
16 67 1 0 0 0 0
17 18 1 0 0 0 0
17 19 1 0 0 0 0
17 46 1 0 0 0 0
18 47 1 0 0 0 0
19 20 1 0 0 0 0
19 32 1 0 0 0 0
19 48 1 0 0 0 0
20 21 1 0 0 0 0
20 49 1 0 0 0 0
21 22 2 0 0 0 0
21 23 1 0 0 0 0
23 24 1 0 0 0 0
24 25 1 0 0 0 0
24 31 1 0 0 0 0
24 50 1 0 0 0 0
25 26 1 0 0 0 0
25 68 1 0 0 0 0
25 69 1 0 0 0 0
26 27 1 0 0 0 0
27 28 1 0 0 0 0
27 31 1 0 0 0 0
27 51 1 0 0 0 0
28 29 1 0 0 0 0
29 30 1 0 0 0 0
29 70 1 0 0 0 0
29 71 1 0 0 0 0
30 31 1 0 0 0 0
30 72 1 0 0 0 0
30 73 1 0 0 0 0
31 52 1 0 0 0 0
32 38 1 0 0 0 0
32 74 1 0 0 0 0
32 75 1 0 0 0 0
33 34 2 0 0 0 0
33 38 1 0 0 0 0
33 53 1 0 0 0 0
34 35 1 0 0 0 0
34 54 1 0 0 0 0
35 36 2 0 0 0 0
35 55 1 0 0 0 0
36 37 1 0 0 0 0
36 56 1 0 0 0 0
37 38 2 0 0 0 0
37 57 1 0 0 0 0
M END
What happen if you add quotes?
My first guess would be that you need to define a variable with the new file name.
Or you do this in one step...
I was trying to attempt this but I do not have a file that gets passed the
cmd.h_add
It started working. But there is still a problem, probably because
'.mol'
is in' '
it doesn't really convert the file, but adds extension to file name. I've tried already to convert one of my files manually and it worked, while in this case file is not converted (same file inside, just file name is different).cmd.h_add
simply adds hydrogens that may be lost etc. This line in not really important for the case, so you can comment it.Could you update your question and add a sample input and output? I am unsure what I am supposed to be seeing when you say it does not convert the files?!
I've updated
Maybe you want to add the full code to your answer below. This will allow others in the future to quickly see the solution without trying for themselves ;)