def optimize(self, shot=0, method="newton", crit=1e-4): """ Optimize the geometry and align the optimized geometry to the starting geometry. """ if os.path.exists("%s.xyz_2" % self.name): os.unlink("%s.xyz_2" % self.name) self.mol[shot].write("%s.xyz" % self.name, ftype="tinker") if method == "newton": if self.rigid: optprog = "optrigid" else: optprog = "optimize" elif method == "bfgs": if self.rigid: optprog = "minrigid" else: optprog = "minimize" o = self.calltinker("%s %s.xyz %f" % (optprog, self.name, crit)) # Silently align the optimized geometry. M12 = Molecule("%s.xyz" % self.name, ftype="tinker") + Molecule("%s.xyz_2" % self.name, ftype="tinker") if not self.pbc: M12.align(center=False) M12[1].write("%s.xyz_2" % self.name, ftype="tinker") rmsd = M12.ref_rmsd(0)[1] cnvgd = 0 mode = 0 for line in o: s = line.split() if len(s) == 0: continue if "Optimally Conditioned Variable Metric Optimization" in line: mode = 1 if "Limited Memory BFGS Quasi-Newton Optimization" in line: mode = 1 if mode == 1 and isint(s[0]): mode = 2 if mode == 2: if isint(s[0]): E = float(s[1]) else: mode = 0 if "Normal Termination" in line: cnvgd = 1 if not cnvgd: for line in o: logger.info(str(line) + "\n") logger.info("The minimization did not converge in the geometry optimization - printout is above.\n") return E, rmsd
def Energy_RMSD(systems): tinkerhome = os.environ["TINKERPATH"] f1 = open("runAna.sh", "w") f2 = open("runMin.sh", "w") i = 0 for sys_ in systems: opts = systems[sys_] optimize = (opts['optimize'] if 'optimize' in opts else False) if not optimize: if (i+1)%24 == 0: cmd = "rm -f %s.out\n%s/analyze %s.xyz -k %s.key E > %s.out \n"%(sys_, os.environ["TINKERPATH"], sys_, sys_, sys_) i += 1 else: cmd = "rm -f %s.out\n%s/analyze %s.xyz -k %s.key E > %s.out & \n"%(sys_, os.environ["TINKERPATH"], sys_, sys_, sys_) i += 1 f1.write(cmd) else: if (i+1)%24 == 0: cmd = "rm -f %s.xyz_2 %s.out \n%s/optimize %s.xyz -k %s.key 0.0001 > %s.out \n"%(sys_, sys_, os.environ["TINKERPATH"], sys_, sys_, sys_) i += 1 else: cmd = "rm -f %s.xyz_2 %s.out \n%s/optimize %s.xyz -k %s.key 0.0001 > %s.out & \n"%(sys_, sys_, os.environ["TINKERPATH"], sys_, sys_, sys_) i += 1 f2.write(cmd) f1.write("wait\n") f2.write("wait\n") f1.close() f2.close() os.system("sh runAna.sh") os.system("sh runMin.sh") for sys_ in systems: while not os.path.isfile(os.path.join(os.getcwd(), sys_ + ".out")): time.sleep(1.0) Es = {} RMSDs = {} for sys_ in systems: energ = 0.0 rmsd = 0.0 for line in open("%s.out"%sys_).readlines(): if "Total Potential Energy" in line: energ = float(line.split()[-2].replace('D','e')) Es[sys_] = energ RMSDs[sys_] = 0.0 if "Final Function Value :" in line: energ = float(line.split()[-1].replace('D','e')) Es[sys_] = energ M1 = Molecule("%s.xyz" % sys_, ftype="tinker") M2 = Molecule("%s.xyz_2" % sys_, ftype="tinker") M1 += M2 RMSDs[sys_] = M1.ref_rmsd(0)[1] return Es,RMSDs
def optimize(self, shot=0, method="newton", crit=1e-4): """ Optimize the geometry and align the optimized geometry to the starting geometry. """ logger.error( 'Geometry optimizations are not yet implemented in AMBER interface' ) raise NotImplementedError # Code from tinkerio.py if os.path.exists('%s.xyz_2' % self.name): os.unlink('%s.xyz_2' % self.name) self.mol[shot].write('%s.xyz' % self.name, ftype="tinker") if method == "newton": if self.rigid: optprog = "optrigid" else: optprog = "optimize" elif method == "bfgs": if self.rigid: optprog = "minrigid" else: optprog = "minimize" o = self.calltinker("%s %s.xyz %f" % (optprog, self.name, crit)) # Silently align the optimized geometry. M12 = Molecule("%s.xyz" % self.name, ftype="tinker") + Molecule( "%s.xyz_2" % self.name, ftype="tinker") if not self.pbc: M12.align(center=False) M12[1].write("%s.xyz_2" % self.name, ftype="tinker") rmsd = M12.ref_rmsd(0)[1] cnvgd = 0 mode = 0 for line in o: s = line.split() if len(s) == 0: continue if "Optimally Conditioned Variable Metric Optimization" in line: mode = 1 if "Limited Memory BFGS Quasi-Newton Optimization" in line: mode = 1 if mode == 1 and isint(s[0]): mode = 2 if mode == 2: if isint(s[0]): E = float(s[1]) else: mode = 0 if "Normal Termination" in line: cnvgd = 1 if not cnvgd: for line in o: logger.info(str(line) + '\n') logger.info( "The minimization did not converge in the geometry optimization - printout is above.\n" ) return E, rmsd