Example #1
0
    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)
Example #2
0
    def test_close_ring_approx(self):
        mol = Geometry(TestGeometry.benzene)

        ref1 = Geometry(TestGeometry.naphthalene)
        mol1 = mol.copy()
        mol1.ring_substitute(['7', '8'], RingFragment('benzene'))
        rmsd = mol1.RMSD(ref1, align=True)
        self.assertTrue(rmsd < rmsd_tol(ref1))

        ref2 = Geometry(TestGeometry.tetrahydronaphthalene)
        mol2 = mol.copy()
        mol2.ring_substitute(['7', '8'], RingFragment('cyclohexane-chair.1'))
        rmsd = mol2.RMSD(ref2, align=True)
        self.assertTrue(rmsd < rmsd_tol(ref2))
Example #3
0
    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))
Example #4
0
    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))
Example #5
0
    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))
Example #6
0
 def test_interpolating_structure(self):
     #test to see if interpolated geometry is correct
     ref = Geometry(prefix + "ref_files/torsion_interpolation.xyz")
     S = Pathway([self.t60, self.t90])
     geom = S.Geom_func(0.4)
     rmsd = geom.RMSD(ref, align=True)
     self.assertTrue(rmsd < rmsd_tol(ref, superLoose=True))
Example #7
0
 def test_interpolating_structure(self):
     # test to see if interpolated geometry is correct
     ref = Geometry(
         os.path.join(prefix, "ref_files", "torsion_interpolation.xyz"))
     pathway = Pathway(self.t60, array([self.t60.coords, self.t90.coords]))
     geom = pathway.geom_func(0.4)
     rmsd = geom.RMSD(ref, align=True, sort=False)
     self.assertTrue(rmsd < rmsd_tol(ref, superLoose=True))
Example #8
0
 def is_NO2(self, sub):
     ref = TestSubstituent.NO2
     self.assertEqual(sub.name, "NO2")
     self.assertEqual(sub.comment, "CF:2,120")
     self.assertEqual(sub.conf_num, 2)
     self.assertEqual(sub.conf_angle, np.deg2rad(120))
     rmsd = ref.RMSD(sub, sort=True, align=True)
     self.assertTrue(rmsd < rmsd_tol(ref, superLoose=True))
     return
Example #9
0
 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))
Example #10
0
 def is_COCH3(self, sub):
     ref = TestSubstituent.COCH3
     self.assertEqual(sub.name, "COCH3")
     self.assertEqual(sub.comment, "CF:2,180")
     self.assertEqual(sub.conf_num, 2)
     self.assertEqual(sub.conf_angle, np.deg2rad(180))
     rmsd = ref.RMSD(sub, longsort=True)
     self.assertTrue(rmsd < rmsd_tol(ref))
     return
Example #11
0
    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))
Example #12
0
    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))
Example #13
0
    def test_substitute(self):
        mol = TestComponent.benz.copy()
        benz_Cl = TestComponent.benz_Cl.copy()
        benz_NO2_Cl = TestComponent.benz_NO2_Cl.copy()
        benz_OH_Cl = TestComponent.benz_OH_Cl.copy()
        benz_Ph_Cl = TestComponent.benz_Ph_Cl.copy()

        mol.substitute(Substituent("Cl"), "11")
        rmsd = mol.RMSD(benz_Cl, sort=True)
        self.assertTrue(rmsd < rmsd_tol(benz_Cl))

        mol.substitute(Substituent("NO2"), "12", "1")
        rmsd = mol.RMSD(benz_NO2_Cl, sort=True)
        self.assertTrue(rmsd < rmsd_tol(benz_NO2_Cl))

        mol.substitute(Substituent("OH"), "NO2")
        rmsd = mol.RMSD(benz_OH_Cl, sort=True)
        self.assertTrue(rmsd < rmsd_tol(benz_OH_Cl))

        mol.substitute(Substituent("Ph"), "12.*")
        rmsd = mol.RMSD(benz_Ph_Cl)
        self.assertTrue(rmsd < rmsd_tol(benz_Ph_Cl))
Example #14
0
    def validate(self, test, ref, thresh=None):
        if thresh is None:
            thresh = rmsd_tol(ref)
        t_el = sorted([t.element for t in test.atoms])
        r_el = sorted([r.element for r in ref.atoms])
        if len(t_el) != len(r_el):
            return False

        for t, r in zip(t_el, r_el):
            if t != r:
                return False

        rmsd = ref.RMSD(test, align=True)
        return rmsd < thresh
Example #15
0
    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))
Example #16
0
    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))
Example #17
0
    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))