Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
tao authored and tao committed May 12, 2020
1 parent 5bb4742 commit 90303cb
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/cons.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""

# Atom number - Atom name map
ELEMENT = {1:"H", 3:"Li", 6:"C", 7:"N", 8:"O", 9:"F", 12: "Mg", 13: "Al", 14:"Si",
ELEMENT = {1:"H", 3:"Li", 5:"B", 6:"C", 7:"N", 8:"O", 9:"F", 12: "Mg", 13: "Al", 14:"Si",
15:"P", 16:"S", 17:"Cl", 20:"Ca", 22:"Ti", 28:"Ni", 31:"Ga", 32:"Ge"}
# Atom name - Atom number map
ELEMENT2ATN = {"H":1, "Li":3, "C":6, "N":7, "O":8, "F":9, "Na":11, 12: "Mg", "Al":13, "Si":14,
Expand All @@ -11,7 +11,7 @@
"Ba": 56, "Y":39, "Zr": 40, "Cu": 29, "K":19, "Br":35, "Cs":55, "Ag":47,
"Ru":44, "He":2, "Au":79, "Cd": 48, "Cr": 24, "Fe": 26, "I": 53, "Mn": 25,
"Pd": 46, "Rh": 45, "Sc": 21, "Tc": 43, "Zn": 30, "W": 74, "Se": 34, "B": 5,
"Mg": 12, "Bi": 83, "Pb": 82, "Ge": 32}
"Mg": 12, "Bi": 83, "Pb": 82, "Ge": 32, "Sr":38, "Rb":37}

# Atom name - Atom mass map
ELEMENT2MASS = {"H": 1.0079, "O": 15.999, "N": 14.007, "Li":6.941, "LI":6.941, "Al": 26.982, "AL": 26.982,
Expand All @@ -27,7 +27,7 @@
"He": 4.0026, "Zn": 65.39, "Tc": 98.907, "Sc": 44.956, "Ru": 101.07, "Rh": 102.906,
"Pd": 106.42, "Mn": 54.938, "Cr": 51.996, "Cd": 112.411, "B": 10.811,
"Ru": 101.07, "RU":101.07, "W": 183.84, "Se": 78.96, "SE": 78.96, "Ir":192.22,
"Pb": 207.20}
"Pb": 207.20, "Sr":87.62, "Rb":85.468}
# Atom name - Atom mass map
MASS2ELMENT = {1.0079: "H",12.011: "C", 14.0067:"N", 15.9994: "O", 24: "Mg", 27: "Al", 28:"Si",
14.0070:"N", 15.9990: "O",
Expand Down
30 changes: 25 additions & 5 deletions lib/g03.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def read(self, filename):
f.close()

def __parse_keyword(self,):
keywords = []
keywords = []
tmp = ''
state = 0
for i in self.methods:
Expand Down Expand Up @@ -233,7 +233,7 @@ def getEnergy(self, ):
if "HF" in i:
ener = float(i[3:])
else:
print "Error: No energy read"
print("Error: No energy read")

# get the zpe energy
zpe = 0
Expand All @@ -245,14 +245,14 @@ def getEnergy(self, ):
f.close()
return ener, zpe

def getCharge(self,):
def getMullikenCharge(self,):
"""get Mulliken charege from QM
"""
charges = []
lines = []
f = open(self.name, "r")
for i in f:
if "Mulliken atomic charges" in i or \
if "Mulliken charges" in i or \
"Total atomic charges" in i:
break
for i in f:
Expand All @@ -265,9 +265,29 @@ def getCharge(self,):
charges.append(tokens)
return charges

def getESPCharge(self,):
"""get ESP charege from QM
"""
charges = []
lines = []
f = open(self.name, "r")
for i in f:
if "ESP charges" in i or \
"Total atomic charges" in i:
break
for i in f:
if "Sum of ESP charges" in i:
break
lines.append(i)
f.close()
for i in lines[1:]:
tokens = i.strip().split()
charges.append(tokens)
return charges

def main():
if len(sys.argv) < 2:
print "g03.py logfile"
print("g03.py logfile")
else:
for i in sys.argv[1:]:
geo = i.split(".")[0]
Expand Down
95 changes: 95 additions & 0 deletions lib/itp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import sys
import copy
import os
import time

def usage():
print("""xxxxx
xxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxx
""")

def parseItpfile(itpfile):
parms = {}
term =''
f = open(itpfile, 'r')
for i in f:
if i.startswith('#') or i.startswith(';'):
pass
elif len(i.strip()) < 1:
pass
elif i.startswith('['):
term = i.split()[1]
if not term in parms:
parms[term] = []
else:
if term !='':
clear_comments = 1
if clear_comments:
if ';' in i:
parms[term].append(i.split(';')[0].split())
else:
parms[term].append(i.split())
f.close()
return parms

def writeItp(itpfile, parms):
o = open(itpfile, 'w')
ISOTIMEFORMAT='%Y-%m-%d %X'
currentTime = time.strftime( ISOTIMEFORMAT, time.localtime( time.time() ) )
#o.write("#CREATED AT%s\n\n"%currentTime)

sections = ['moleculetype', 'atoms', 'bonds', 'angles', 'dihedrals']
for i in sections:
if i in parms.keys():
o.write("[ %s ]\n"%i)
for ii in parms[i]:
line = ''
for iii in ii:
line += iii + ' '
line += '\n'
o.write(line)
o.close()

def parmModify(parm, deltaS,epsilonS, term, atomtype):
parmM = {}
for (i,j) in parm.items():
parmM[i] = parm[i]
parmM[term] = []
for j in parm[term]:
m = copy.copy(j)
if j[0] == atomtype:
m[4] = "%.4f"%(float(j[4])*deltaS/100)
m[5] = "%.4f"%(float(j[5])*epsilonS/100)
parmM[term].append(m)
return parmM

def scanAll(parm, itpfile):
folder = os.getcwd()
term = "atomtypes"
atom = []
for i in parm[term]:
atom.append(i[0])
delta = [105, 100, 95]
epsilon = [120, 100, 80]
for a in atom:
for i in delta:
for j in epsilon:
fullname = os.path.join(folder,'%s_%03d_%03d'%(a,i,j))
parmM = parmModify(parm, i,j, term, a)
if os.path.isdir(fullname):
pass
else:
os.system("mkdir %s"%fullname)
os.system("cp run.gro run.mdp *.top grompp.sh %s"%fullname)
outitpfile = os.path.join(fullname, itpfile)
writeItp(outitpfile, parmM)

if __name__ == "__main__":
if len(sys.argv) < 2:
usage()
else:
itpfile = sys.argv[1]
parmOr = parseItpfile(itpfile)
writeItp('test.itp', parmOr)
#scanAll(parmOr, itpfile)
4 changes: 2 additions & 2 deletions lib/output_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def toPoscar(system, outfile="POSCAR"):
s = system
o = open(outfile, "w")
ndx = open(ndxfile, 'w')
ndx.write('# original-id new-id\n')
ndx.write('# new-id old-id\n')
o.write("%s\n"%s.name)
o.write("%20.15f\n"%s.scaleFactor)

Expand Down Expand Up @@ -396,7 +396,7 @@ def toPoscar(system, outfile="POSCAR"):
natom += 1

for i in range(natom):
ndx.write('%d %d\n'%(i+1, id_numbers[i]))
ndx.write('%d %d\n'%(id_numbers[i], i+1))
xf = coords[i][0]
yf = coords[i][1]
zf = coords[i][2]
Expand Down
8 changes: 8 additions & 0 deletions molecules/ase/get_mol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from ase.build import molecule
from ase.collections import g2
from ase.io import write

for i in g2.names:
atoms = molecule(i)
write(i+'.pdb', atoms)

9 changes: 5 additions & 4 deletions tools/rdkit/mol2xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
n_atoms = int(tokens[0])

coords = []
for i in range(4, 4+n_atoms):
for i in range(len(lines)):
tokens = lines[i].strip().split()
line = '%s %s %s %s\n'%(tokens[3], tokens[0], tokens[1], tokens[2])
coords.append(line)
if len(tokens) == 16:
line = '%s %s %s %s\n'%(tokens[3], tokens[0], tokens[1], tokens[2])
coords.append(line)

o = open('%s.xyz'%sys.argv[1], 'w')
o.write('%d\n\n'%n_atoms)
o.write('%d\n\n'%len(coords))
for i in coords:
o.write(i)
o.close()
Expand Down
2 changes: 0 additions & 2 deletions tools/vasp/get_potcar.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@
POT_DATA_BASE = "/p/home/taocheng/src/vasp/vasp.5.3/potcar/potpaw_PBE"
elif socket.gethostname() == "tao-ThinkCentre-M79":
POT_DATA_BASE = "/home/tao/src/vasp/vasp.5.3.5/potcar/potpaw_PBE"
elif socket.gethostname() == "tao-ThinkCentre-M79":
POT_DATA_BASE = "/home/tao/src/vasp/vasp.5.3.5/potcar/potpaw_PBE"
elif socket.gethostname() == "tao-Precision-Tower-3420-ubuntu":
POT_DATA_BASE = "/home/tao/data/soft/vasp/vasp.5.3.5/potcar/potpaw_PBE"
elif socket.gethostname() == "mu05":
Expand Down

0 comments on commit 90303cb

Please sign in to comment.