From 90303cb61f6fe234801cc9d645041088b19c6a85 Mon Sep 17 00:00:00 2001 From: tao Date: Mon, 11 May 2020 17:56:50 -0700 Subject: [PATCH] update --- lib/cons.py | 6 +-- lib/g03.py | 30 ++++++++++--- lib/itp.py | 95 ++++++++++++++++++++++++++++++++++++++++ lib/output_conf.py | 4 +- molecules/ase/get_mol.py | 8 ++++ tools/rdkit/mol2xyz.py | 9 ++-- tools/vasp/get_potcar.py | 2 - 7 files changed, 138 insertions(+), 16 deletions(-) create mode 100644 lib/itp.py create mode 100644 molecules/ase/get_mol.py diff --git a/lib/cons.py b/lib/cons.py index ba7441e..7af88cd 100644 --- a/lib/cons.py +++ b/lib/cons.py @@ -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, @@ -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, @@ -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", diff --git a/lib/g03.py b/lib/g03.py index 15f1dc7..72c394c 100644 --- a/lib/g03.py +++ b/lib/g03.py @@ -151,7 +151,7 @@ def read(self, filename): f.close() def __parse_keyword(self,): - keywords = [] + keywords = [] tmp = '' state = 0 for i in self.methods: @@ -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 @@ -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: @@ -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] diff --git a/lib/itp.py b/lib/itp.py new file mode 100644 index 0000000..c05a1c4 --- /dev/null +++ b/lib/itp.py @@ -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) diff --git a/lib/output_conf.py b/lib/output_conf.py index 54fd56a..94708fd 100644 --- a/lib/output_conf.py +++ b/lib/output_conf.py @@ -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) @@ -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] diff --git a/molecules/ase/get_mol.py b/molecules/ase/get_mol.py new file mode 100644 index 0000000..acdbbcf --- /dev/null +++ b/molecules/ase/get_mol.py @@ -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) + diff --git a/tools/rdkit/mol2xyz.py b/tools/rdkit/mol2xyz.py index 44161cf..fe7aaba 100644 --- a/tools/rdkit/mol2xyz.py +++ b/tools/rdkit/mol2xyz.py @@ -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() diff --git a/tools/vasp/get_potcar.py b/tools/vasp/get_potcar.py index 27e6d6a..e1f09e1 100755 --- a/tools/vasp/get_potcar.py +++ b/tools/vasp/get_potcar.py @@ -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":