def check_geometry_rmsd(self, *args): """check RMSD between energy and frequency filereader on the absolute tab if the RMSD is > 10^-5 or the number of atoms is different, put a warning in the status bar""" if self.thermo_selector.currentIndex( ) >= 0 and self.sp_selector.currentIndex() >= 0: fr = self.sp_selector.currentData() fr2 = self.thermo_selector.currentData() if len(fr.atoms) != len(fr2.atoms): self.status.showMessage( "structures are not the same: different number of atoms") return geom = Geometry(fr) geom2 = Geometry(fr2) rmsd = geom.RMSD(geom2) if not isclose(rmsd, 0, atol=10**-5): rmsd = geom.RMSD(geom2, sort=True) if not isclose(rmsd, 0, atol=10**-5): self.status.showMessage( "structures might not be the same - RMSD = %.4f" % rmsd) else: self.status.showMessage("")
def test_interpolate(self): """test interpolate.py assumes current working directory is writable b/c interpolate doesn't print structures to stdout""" ref = Geometry( os.path.join(prefix, "ref_files", "torsion_interpolation.xyz")) args = [ sys.executable, os.path.join(self.aarontools_bin, "interpolate.py"), TestCLS.t60, TestCLS.t90, "-t", "0.40", "-u", ] proc = Popen(args, stdout=PIPE, stderr=PIPE) out, err = proc.communicate() if len(err) != 0: raise RuntimeError(err) mol = Geometry("traj-0.xyz") os.remove("traj-0.xyz") rmsd = mol.RMSD(ref, align=True, sort=True) self.assertTrue(rmsd < rmsd_tol(ref, superLoose=True))
def test_changeChirality(self): """test changeChirality.py""" args = [ sys.executable, os.path.join(self.aarontools_bin, "changeChirality.py"), TestCLS.change_chir_1, "--diastereomers", ] proc = Popen(args, stdout=PIPE, stderr=PIPE) out, err = proc.communicate() if len(err) != 0: raise RuntimeError(err) fr = FileReader(("out", "xyz", out.decode("utf-8")), get_all=True) for step, ref in zip(fr.all_geom, self.change_chir_ref_1): geom = None for item in step: if isinstance(item, list) and all( isinstance(a, Atom) for a in item): geom = Geometry(item) if geom is None: raise RuntimeError("an output is missing atoms") ref_geom = Geometry(ref) rmsd = ref_geom.RMSD(geom) self.assertTrue(rmsd < rmsd_tol(ref_geom))
def test_RMSD(self): ref = Geometry(TestGeometry.benz_NO2_Cl) # RMSD of copied object should be 0 test = ref.copy() self.assertTrue(validate(test, ref)) # RMSD of shifted copy should be 0 test = ref.copy() test.coord_shift([1, 2, 3]) self.assertTrue(validate(test, ref)) # RMSD of rotated copy should be 0 test = ref.copy() test.rotate([1, 2, 3], 2.8) self.assertTrue(validate(test, ref)) # RMSD of two different structures should not be 0 test = Geometry(TestGeometry.pentane) self.assertFalse(validate(test, ref)) # RMSD of similar molecule test = Geometry(TestGeometry.benzene) res = ref.RMSD(test, targets="C", ref_targets="C") self.assertTrue(res < rmsd_tol(ref))
def test_RMSD(self): ref = Geometry(TestGeometry.benz_NO2_Cl) # RMSD of copied object should be 0 other = ref.copy() self.assertTrue(ref.RMSD(other) < rmsd_tol(ref, superTight=True)) # if they are out of order, sorting should help res = ref.RMSD(other, longsort=True) self.assertTrue(res < rmsd_tol(other, superTight=True)) # RMSD of shifted copy should be 0 other = ref.copy() other.coord_shift([1, 2, 3]) self.assertTrue(ref.RMSD(other) < rmsd_tol(ref, superTight=True)) # RMSD of rotated copy should be 0 other = ref.copy() other.rotate([1, 2, 3], 2.8) other.write("tmp") self.assertTrue(ref.RMSD(other) < rmsd_tol(ref)) # RMSD of two different structures should not be 0 other = Geometry(TestGeometry.pent) self.assertTrue(ref.RMSD(other) > 10**-2) # RMSD of similar molecule other = Geometry(TestGeometry.benzene) res = ref.RMSD(other, targets="C", ref_targets="C") self.assertTrue(res < rmsd_tol(ref)) res = ref.RMSD(other, sort=True)
def test_close_ring_rmsd(self): mol = Geometry(TestGeometry.naphthalene) ref = Geometry(TestGeometry.pyrene) targets1 = mol.find(['9', '15']) targets2 = mol.find(['10', '16']) mol.ring_substitute(targets1, RingFragment('benzene')) mol.ring_substitute(targets2, RingFragment('benzene')) rmsd = mol.RMSD(ref, align=True) self.assertTrue(rmsd < rmsd_tol(ref))
def test_substitute(self): ref = Geometry(TestGeometry.benz_NO2_Cl) mol = Geometry(TestGeometry.benzene) mol.substitute(Substituent("NO2"), "12") mol.substitute(Substituent("Cl"), "11") rmsd = mol.RMSD(ref, align=True) self.assertTrue(rmsd < rmsd_tol(ref))
def test_mirror(self): """test mirror.py""" ref1 = Geometry(TestCLS.chiral_ring_mirror) args = [ sys.executable, os.path.join(self.aarontools_bin, "mirror.py"), TestCLS.change_chir_1, "-xy", ] proc = Popen(args, stdout=PIPE, stderr=PIPE) out, err = proc.communicate() if len(err) != 0: raise RuntimeError(err) fr = FileReader(("out", "xyz", out.decode("utf-8"))) mol = Geometry(fr) rmsd = mol.RMSD(ref1, sort=True) self.assertTrue(rmsd < rmsd_tol(ref1, superLoose=True))
def test_close_ring(self): mol = Geometry(TestGeometry.benzene) ref1 = Geometry(TestGeometry.naphthalene) mol1 = mol.copy() mol1.ring_substitute(["7", "8"], Ring("benzene")) self.assertTrue(validate(mol1, ref1, thresh="loose")) ref2 = Geometry(TestGeometry.tetrahydronaphthalene) mol2 = mol.copy() mol2.ring_substitute(["7", "8"], Ring("cyclohexane")) rmsd = mol2.RMSD(ref2, align=True, sort=True) self.assertTrue(rmsd < rmsd_tol(ref2, superLoose=True)) mol3 = Geometry(TestGeometry.naphthalene) ref3 = Geometry(TestGeometry.pyrene) targets1 = mol3.find(["9", "15"]) targets2 = mol3.find(["10", "16"]) mol3.ring_substitute(targets1, Ring("benzene")) mol3.ring_substitute(targets2, Ring("benzene")) rmsd = mol3.RMSD(ref3, align=True, sort=True) self.assertTrue(rmsd < rmsd_tol(ref3, superLoose=True))
def test_closeRing(self): """test closeRing.py""" ref1 = Geometry(TestCLS.naphthalene) args = [ sys.executable, os.path.join(self.aarontools_bin, "closeRing.py"), TestCLS.benzene, "-r", "7", "8", "benzene", ] proc = Popen(args, stdout=PIPE, stderr=PIPE) out, err = proc.communicate() if len(err) != 0: raise RuntimeError(err) fr = FileReader(("out", "xyz", out.decode("utf-8"))) mol = Geometry(fr) rmsd = mol.RMSD(ref1, sort=True) self.assertTrue(rmsd < rmsd_tol(ref1, superLoose=True))
s = "" for ele in elements: s += "%s%i" % (ele, element_list.count(ele)) if not any(s == key for key in structures[n_atoms].keys()): structures[n_atoms][s] = [] dup = False for group in structures[n_atoms][s]: for struc, _, _ in group: if args.energy_filter and "energy" in geom.other and "energy" in struc.other: d_nrg = UNIT.HART_TO_KCAL * abs(geom.other["energy"] - struc.other["energy"]) if d_nrg > args.energy_filter: continue rmsd = geom.RMSD(struc, sort=True) if rmsd < args.tol: dup = True group.append((geom, rmsd, False)) break if args.mirror: rmsd2 = geom_mirrored.RMSD(struc, sort=True) if rmsd2 < args.tol: dup = True group.append(geom, rmsd2, True) if dup: break if not dup: structures[n_atoms][s].append([(geom, 0, False)])
if args.input_format is not None: infile = FileReader((f, args.input_format, None)) else: infile = FileReader(f) else: if args.input_format is not None: infile = FileReader(("from stdin", args.input_format, f)) else: infile = FileReader(("from stdin", "xyz", f)) geom = Geometry(infile) # align rmsd = geom.RMSD(ref_geom, align=True, targets=args.in_target, ref_targets=args.ref_target, heavy_only=args.heavy, sort=args.sort) geom.comment = "rmsd = %f" % rmsd if not args.value_only and not args.csv: if args.outfile: outfile = args.outfile if "$INFILE" in outfile: outfile = outfile.replace("$INFILE", get_filename(f)) geom.write(append=True, outfile=outfile) else: print(geom.write(outfile=False)) elif args.value_only:
ref_G = Geometry(freq_file) freq_centroid = ref_G.COM(mass_weight=True) ref_G.coord_shift(vector = -1*freq_centroid) Q = [data.vector for data in freq_file.other['frequency'].data] else: ref_G = Gs[0] Q = None """ ref_G = Gs[0] Q = None #align all input geometries to the reference for G in Gs: centroid = G.COM(mass_weight=True) G.coord_shift(vector = -1*centroid) G.RMSD(ref=ref_G, align=True) #interpolate between the structures S = Pathway(Gs, Q) s_max, r_max = Pathway.t_to_s(1, S.region_length) #header for writing energies nrg_out = " t E dE/dt\n" #list of geometries to print write_geoms = [] if args.print_max or args.print_min: #to find minima and maxima, find where derivative crosses 0 and #sign of derivative at neighboring points max_n_min_ts = [] ts = np.linspace(0, 1, num=10001)
warn("targets may need to be specified for both input and reference") for f in args.infile: if isinstance(f, str): if args.input_format is not None: infile = FileReader((f, args.input_format[0], None)) else: infile = FileReader(f) else: if args.input_format is not None: infile = FileReader(('from stdin', args.input_format[0], f)) else: rmsd_parser.print_help() raise RuntimeError( "when no input file is given, stdin is read and a format must be specified" ) geom = Geometry(infile) #align rmsd = geom.RMSD(ref_geom, align=True, targets=args.in_target, ref_targets=args.ref_target) geom.comment = "rmsd = %f" % rmsd s = FileWriter.write_xyz(geom, append=True, outfile=args.outfile[0]) if not args.outfile[0]: print(s)
) if "frequency" not in infile.other: warn("no frequencies in %s - skipping" % f) continue freq = infile.other["frequency"] co = CompOutput(infile, ) if sp_nrg is None: nrg = co.energy else: nrg = sp_nrg sp_geom = Geometry(sp_file) freq_geom = Geometry(infile) rmsd = sp_geom.RMSD(freq_geom) if not isclose(rmsd, 0, atol=1e-5): warn( "\ngeometries in supposed single-point/thermochemistry pair appear\n" + "to be different (rmsd = %.5f)\n" % rmsd + "%s\n%s" % (sp_geom.name, freq_geom.name)) dE, dH, s = co.therm_corr(temperature=args.temp) if freq.anharm_data: ZPVE_anh = co.calc_zpe(anharmonic=True) rrho_dG = co.calc_G_corr(v0=0, temperature=args.temp, method="RRHO") qrrho_dG = co.calc_G_corr(v0=args.w0, temperature=args.temp, method="QRRHO") qharm_dG = co.calc_G_corr(v0=args.w0, temperature=args.temp,
def test_rotate(self): """test rotate.py""" ref = Geometry(TestCLS.chlorotoluene_ref) # range of targets args = [ sys.executable, os.path.join(self.aarontools_bin, "rotate.py"), TestCLS.chlorotoluene, "-b", "3", "12", "-c", "3", "-t", "12-15", "-a", "180", ] proc = Popen(args, stdout=PIPE, stderr=PIPE) out, err = proc.communicate() if len(err) != 0: raise RuntimeError(err) fr = FileReader(("out", "xyz", out.decode("utf-8"))) mol = Geometry(fr) rmsd = mol.RMSD(ref, align=True) self.assertTrue(rmsd < rmsd_tol(ref)) # enumerate all targets args = [ sys.executable, os.path.join(self.aarontools_bin, "rotate.py"), TestCLS.chlorotoluene, "-b", "3", "12", "-c", "3", "-t", "12,13,14,15", "-a", "180", ] proc = Popen(args, stdout=PIPE, stderr=PIPE) out, err = proc.communicate() if len(err) != 0: raise RuntimeError(err) fr = FileReader(("out", "xyz", out.decode("utf-8"))) mol = Geometry(fr) rmsd = mol.RMSD(ref, align=True) self.assertTrue(rmsd < rmsd_tol(ref)) # rotate all atom by 180 - rmsd should be basically 0 ref2 = Geometry(TestCLS.chlorotoluene) args = [ sys.executable, os.path.join(self.aarontools_bin, "rotate.py"), TestCLS.chlorotoluene, "-x", "x", "-a", "180", ] proc = Popen(args, stdout=PIPE, stderr=PIPE) out, err = proc.communicate() if len(err) != 0: raise RuntimeError(err) fr = FileReader(("out", "xyz", out.decode("utf-8"))) mol = Geometry(fr) rmsd = mol.RMSD(ref2, align=True) self.assertTrue(rmsd < rmsd_tol(ref2)) # rotate one fragment ref3 = Geometry(TestCLS.benzene_dimer_ref) args = [ sys.executable, os.path.join(self.aarontools_bin, "rotate.py"), TestCLS.benzene_dimer, "-p", "1-12", "-c", "1-12", "-f", "1", "-a", "10", ] proc = Popen(args, stdout=PIPE, stderr=PIPE) out, err = proc.communicate() if len(err) != 0: raise RuntimeError(err) fr = FileReader(("out", "xyz", out.decode("utf-8"))) mol = Geometry(fr) rmsd = mol.RMSD(ref3, align=True) self.assertTrue(rmsd < rmsd_tol(ref3))
def test_printXYZ(self): """test printXYZ.py""" # for each test, the rmsd tolerance is determined based on the number of atoms and # the precision we use when printing xyz files # test xyz file ref_xyz = Geometry(TestCLS.xyz_file) args = [ sys.executable, os.path.join(self.aarontools_bin, "printXYZ.py"), TestCLS.xyz_file, ] proc = Popen(args, stdout=PIPE, stderr=PIPE) out, err = proc.communicate() if len(err) != 0: raise RuntimeError(err) fr = FileReader(("out", "xyz", out.decode("utf-8"))) mol = Geometry(fr) rmsd = mol.RMSD(ref_xyz, align=True) self.assertTrue(rmsd < len(ref_xyz.atoms) * (3 * 1e-5)) # test gaussian input file ref_com = Geometry(TestCLS.g09_com_file) args = [ sys.executable, os.path.join(self.aarontools_bin, "printXYZ.py"), TestCLS.g09_com_file, ] proc = Popen(args, stdout=PIPE, stderr=PIPE) out, err = proc.communicate() if len(err) != 0: raise RuntimeError(err) fr = FileReader(("out", "xyz", out.decode("utf-8"))) mol = Geometry(fr) rmsd = mol.RMSD(ref_com, align=True) self.assertTrue(rmsd < len(ref_com.atoms) * (3 * 1e-5)) # test gaussian output file ref_log = Geometry(TestCLS.g09_log_file) args = [ sys.executable, os.path.join(self.aarontools_bin, "printXYZ.py"), TestCLS.g09_log_file, ] proc = Popen(args, stdout=PIPE, stderr=PIPE) out, err = proc.communicate() if len(err) != 0: raise RuntimeError(err) fr = FileReader(("out", "xyz", out.decode("utf-8"))) mol = Geometry(fr) rmsd = mol.RMSD(ref_log, align=True) self.assertTrue(rmsd < len(ref_log.atoms) * (3 * 1e-5)) # test orca output file ref_out = Geometry(TestCLS.orca_out_file) args = [ sys.executable, os.path.join(self.aarontools_bin, "printXYZ.py"), TestCLS.orca_out_file, ] proc = Popen(args, stdout=PIPE, stderr=PIPE) out, err = proc.communicate() if len(err) != 0: raise RuntimeError(err) fr = FileReader(("out", "xyz", out.decode("utf-8"))) mol = Geometry(fr) rmsd = mol.RMSD(ref_out, align=True) self.assertTrue(rmsd < len(ref_out.atoms) * (3 * 1e-5)) # test psi4 output files and format flat ref_dat = Geometry(FileReader((TestCLS.psi4_dat_file, "dat", None))) args = [ sys.executable, os.path.join(self.aarontools_bin, "printXYZ.py"), TestCLS.psi4_dat_file, "-if", "dat", ] proc = Popen(args, stdout=PIPE, stderr=PIPE) out, err = proc.communicate() if len(err) != 0: raise RuntimeError(err) fr = FileReader(("out", "xyz", out.decode("utf-8"))) mol = Geometry(fr) rmsd = mol.RMSD(ref_dat, align=True) self.assertTrue(rmsd < len(ref_dat.atoms) * (3 * 1e-5))
len(geom_list), (1 - len(geom_list)) * "s" ) ) warn("use the -u option to include structures without an associated energy") sys.exit(0) ref_geom = geom_list[0] if len(nrg_list) < len(geom_list): nrg_list = np.zeros(len(geom_list)) #align all input geometries to the reference for geom, nrg in zip(geom_list, nrg_list): centroid = geom.COM(mass_weight=True) geom.coord_shift(vector=-1 * centroid) geom.RMSD(ref=ref_geom, align=True) #interpolate between the structures pathway = Pathway( ref_geom, np.array([geom.coords for geom in geom_list]), other_vars={"energy": nrg_list} ) s_max, r_max = Pathway.t_to_s(1, pathway.region_length) #header for writing energies nrg_out = "t\tE\tdE/dt\n" #list of geometries to print write_geoms = [] if args.print_max or args.print_min: