Example #1
0
    def test_from_string(self):
        ans = """5
H4 C1
C 0.000000 0.000000 0.000000
H 0.000000 0.000000 1.089000
H 1.026719 0.000000 -0.363000
H -0.513360 -0.889165 -0.363000
H -0.513360 0.889165 -0.363000"""
        xyz = XYZ.from_string(ans)
        mol = xyz.molecule
        sp = ["C", "H", "H", "H", "H"]
        for i, site in enumerate(mol):
            self.assertEqual(site.species_string, sp[i])
            self.assertEqual(len(site.coords), 3)
            if i == 0:
                self.assertTrue(all([c == 0 for c in site.coords]))

        mol_str = """2
Random
C 2.39132145462 -0.700993488928 -7.22293142224e-06
C 1.16730636786 -1.38166622735 -2.77112970359e-06
"""
        xyz = XYZ.from_string(mol_str)
        mol = xyz.molecule
        self.assertTrue(abs(mol[0].z) < 1e-5)
        self.assertTrue(abs(mol[1].z) < 1e-5)
Example #2
0
    def test_from_string(self):
        ans = """5
H4 C1
C 0.000000 0.000000 0.000000
H 0.000000 0.000000 1.089000
H 1.026719 0.000000 -0.363000
H -0.513360 -0.889165 -0.363000
H -0.513360 0.889165 -0.363000"""
        xyz = XYZ.from_string(ans)
        mol = xyz.molecule
        sp = ["C", "H", "H", "H", "H"]
        for i, site in enumerate(mol):
            self.assertEqual(site.species_string, sp[i])
            self.assertEqual(len(site.coords), 3)
            if i == 0:
                self.assertTrue(all([c == 0 for c in site.coords]))

        mol_str = """2
Random
C 2.39132145462 -0.700993488928 -7.22293142224e-06
C 1.16730636786 -1.38166622735 -2.77112970359e-06
"""
        xyz = XYZ.from_string(mol_str)
        mol = xyz.molecule
        self.assertTrue(abs(mol[0].z) < 1e-5)
        self.assertTrue(abs(mol[1].z) < 1e-5)
Example #3
0
    def test_from_string(self):
        ans = """5
H4 C1
C 0.000000 0.000000 0.000000
H 0.000000 0.000000 1.089000
H 1.026719 0.000000 -0.363000
H -0.513360 -0.889165 -0.363000
H -0.513360 0.889165 -0.363000"""
        xyz = XYZ.from_string(ans)
        mol = xyz.molecule
        sp = ["C", "H", "H", "H", "H"]
        for i, site in enumerate(mol):
            self.assertEqual(site.species_string, sp[i])
            self.assertEqual(len(site.coords), 3)
            if i == 0:
                self.assertTrue(all([c == 0 for c in site.coords]))

        mol_str = """2
Random
C 2.39132145462 -0.700993488928 -7.22293142224e-06
C 1.16730636786 -1.38166622735 -2.77112970359e-06
"""
        xyz = XYZ.from_string(mol_str)
        mol = xyz.molecule
        self.assertTrue(abs(mol[0].z) < 1e-5)
        self.assertTrue(abs(mol[1].z) < 1e-5)

        mol_str = """3
Random
C   0.000000000000E+00  2.232615992397E+01  0.000000000000E+00
C  -2.383225420567E-31  1.116307996198E+01  1.933502166311E+01
C  -4.440892098501D-01 -1.116307996198d+01  1.933502166311E+01
"""
        xyz = XYZ.from_string(mol_str)
        mol = xyz.molecule
        self.assertAlmostEqual(mol[0].x, 0)
        self.assertAlmostEqual(mol[1].y, 11.16307996198)
        self.assertAlmostEqual(mol[2].x, -0.4440892098501)
        self.assertAlmostEqual(mol[2].y, -11.16307996198)
        # self.assertTrue(abs(mol[1].z) < 1e-5)

        mol_str = """    5
C32-C2-1                                                                        
 C     2.70450   1.16090  -0.14630     1     3    23     2
 C     1.61930   1.72490  -0.79330     2     1     5    26
 C     2.34210   1.02670   1.14620     3     1     8     6
 C    -0.68690   2.16170  -0.13790     4     5    18     7
 C     0.67160   2.15830   0.14350     5     4     2     6
 """
        xyz = XYZ.from_string(mol_str)
        mol = xyz.molecule
        self.assertAlmostEqual(mol[0].x, 2.70450)
        self.assertAlmostEqual(mol[1].y, 1.72490)
        self.assertAlmostEqual(mol[2].x, 2.34210)
        self.assertAlmostEqual(mol[3].z, -0.13790)
Example #4
0
def insert_solvents(coll):
    names = """THF
    monoglyme
    Dimethylacetamide
    propylene carbonate
    ethylene carbonate
    dimethylcarbonate
    DMSO
    ACN
    Diethylcarbonate
    propyl glyme
    ethyl glyme
    ethyl diglyme
    diglyme
    Butyldiglyme
    tetraglyme
    Pentaethylene glycol diethyl ether
    Tetraethylene glycol diethyl ether
    Tetraethylene glycol dibutyl ether
    Butyldiglyme"""

    for n in names.split("\n"):
        response = requests.get(
            "http://cactus.nci.nih.gov/chemical/structure/{}/file?format=xyz".
            format(n))
        if response.status_code == 200:
            xyz = XYZ.from_string(response.text)
            clean_mol = xyz.molecule
            bb = BabelMolAdaptor(clean_mol)
            pbmol = pb.Molecule(bb.openbabel_mol)
            smiles = pbmol.write("smi").split()[0]
            can = pbmol.write("can").split()[0]
            inchi = pbmol.write("inchi")
            svg = pbmol.write("svg")

            d = {"molecule": clean_mol.as_dict()}
            comp = clean_mol.composition
            d["pretty_formula"] = comp.reduced_formula
            d["formula"] = comp.formula
            d["composition"] = comp.as_dict()
            d["elements"] = list(comp.as_dict().keys())
            d["nelements"] = len(comp)
            d["charge"] = clean_mol.charge
            d["spin_multiplicity"] = clean_mol.spin_multiplicity
            d["smiles"] = smiles
            d["can"] = can
            d["inchi"] = inchi
            # d["names"] = get_nih_names(smiles)
            d["svg"] = svg
            d["xyz"] = str(xyz)
            d["tags"] = ["Solvents"]
            coll.update(
                {
                    "inchi": inchi,
                    "charge": clean_mol.charge,
                    "spin_multiplicity": clean_mol.spin_multiplicity
                }, {"$set": d},
                upsert=True)
        else:
            print("{} not found.\n".format(n))
Example #5
0
    def test_from_string(self):
        ans = """5
H4 C1
C 0.000000 0.000000 0.000000
H 0.000000 0.000000 1.089000
H 1.026719 0.000000 -0.363000
H -0.513360 -0.889165 -0.363000
H -0.513360 0.889165 -0.363000"""
        xyz = XYZ.from_string(ans)
        mol = xyz.molecule
        sp = ["C", "H", "H", "H", "H"]
        for i, site in enumerate(mol):
            self.assertEqual(site.species_string, sp[i])
            self.assertEqual(len(site.coords), 3)
            if i == 0:
                self.assertTrue(all([c == 0 for c in site.coords]))

        mol_str = """2
Random
C 2.39132145462 -0.700993488928 -7.22293142224e-06
C 1.16730636786 -1.38166622735 -2.77112970359e-06
"""
        xyz = XYZ.from_string(mol_str)
        mol = xyz.molecule
        self.assertTrue(abs(mol[0].z) < 1e-5)
        self.assertTrue(abs(mol[1].z) < 1e-5)

        mol_str = """3
Random
C   0.000000000000E+00  2.232615992397E+01  0.000000000000E+00
C  -2.383225420567E-31  1.116307996198E+01  1.933502166311E+01
C  -4.440892098501D-01 -1.116307996198d+01  1.933502166311E+01
"""
        xyz = XYZ.from_string(mol_str)
        mol = xyz.molecule
        self.assertAlmostEqual(mol[0].x, 0)
        self.assertAlmostEqual(mol[1].y, 11.16307996198)
        self.assertAlmostEqual(mol[2].x, -0.4440892098501)
        self.assertAlmostEqual(mol[2].y, -11.16307996198)
Example #6
0
 def set_struct_fromxyz(self, xyzstr):
     self.xyz = xyzstr
     self.struct = XYZ.from_string(xyzstr).molecule.as_dict()
     self.boundary = "0d"