-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdb2mol.py
More file actions
executable file
·81 lines (69 loc) · 2.12 KB
/
pdb2mol.py
File metadata and controls
executable file
·81 lines (69 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/python
# Arnfinn Hykkerud Steindal, Tromso Dec 2011
# Make a xyz file out of a pdb file
import sys
import argparse as ap
parser = ap.ArgumentParser()
parser.add_argument("-i", "--input",dest="filename", required=True, help="the file to read")
parser.add_argument("-b", "--basis",dest="basisset", default='6-31+G*', help="the basisset [default: %(default)s].")
args = parser.parse_args()
basis = args.basisset
pdbfile = open(args.filename,'r')
lines=pdbfile.readlines()
pdbfile.close()
k=0
body=''
charge=0
for i in lines:
if i[0:6]=='HETATM' or i[0:4]=='ATOM':
k=k+1
line=i[77]+str(k)+' '+i[30:38]+' '+i[38:46]+' '+i[46:54]+'\n'
body=body+line
try:
if i[79]=="+":
charge=charge+1
elif i[79]=="-":
charge=charge-1
except:
charge=charge
#out.write(str(k)+'\n'+str(charge)+'\n'+body)
xyzfile=str(k)+'\n\n'+body
all = [['C','',0,'6.0'],['N','',0,'7.0'],['O','',0,'8.0'],['S','',0,'16.0'],['H','',0,'1.0']]
fact = len(all)
inp=xyzfile.split('\n')
for i in inp:
words = i.split()
for j in range(fact):
try:
atom=words[0][0]
if atom== all[j][0]:
newline=words[0]+fact*' '+words[1]+fact*' '+'\
'+words[2]+fact*' '+words[3]+'\n'
all[j][1] = all[j][1] + newline
all[j][2] = all[j][2] + 1
except:
break
atmtps = 0
for j in range(fact):
if all[j][2]>0:
atmtps = atmtps + 1
a=len(args.filename)
mol=open(args.filename[0:a-4]+'.mol','w')
mol.write('BASIS\n\
'+basis+'\n\
Structure from file '+args.filename+'\n\
----------------------\n\
AtomTypes='+str(atmtps)+' NoSymmetry Angstrom')
if charge==0:
mol.write('\n')
else:
print "WARNING!"
print "The total charge of the molecule(s) is (are)"
print "found to be "+str(charge) + " in file " + args.filename
print "Please be sure this is correct."
mol.write(' Charge='+str(charge)+'\n')
for j in range(fact):
if all[j][2]>0:
mol.write(' Charge='+all[j][3]+' Atoms='+str(all[j][2])+'\n')
mol.write(all[j][1])
mol.close()