Beispiel #1
0
 def test_init(self):
     mol = Molecule(["C", "H", "H", "H", "H"], self.coords)
     gau = GaussianInput(mol, charge=1, route_parameters={'SP': "",
                                                          "SCF": "Tight"})
     self.assertEqual(gau.spin_multiplicity, 2)
     mol = Molecule(["C", "H", "H", "H", "H"], self.coords, charge=-1)
     gau = GaussianInput(mol, route_parameters={'SP': "", "SCF": "Tight"})
     self.assertEqual(gau.spin_multiplicity, 2)
     self.assertRaises(ValueError, GaussianInput, mol, spin_multiplicity=1)
Beispiel #2
0
def write_mol(mol, filename):
    """
    Write a molecule to a file based on file extension. For example, anything
    ending in a "xyz" is assumed to be a XYZ file. Supported formats include
    xyz, Gaussian input (gjf|g03|g09|com|inp), and pymatgen's JSON serialized
    molecules.

    Args:
        mol (Molecule/IMolecule): Molecule to write
        filename (str): A filename to write to.
    """
    fname = os.path.basename(filename)
    if fnmatch(fname.lower(), "*.xyz*"):
        return XYZ(mol).write_file(filename)
    elif any([
            fnmatch(fname.lower(), "*.{}*".format(r))
            for r in ["gjf", "g03", "g09", "com", "inp"]
    ]):
        return GaussianInput(mol).write_file(filename)
    elif fnmatch(fname, "*.json*") or fnmatch(fname, "*.mson*"):
        with zopen(filename, "w") as f:
            return json.dump(mol, f, cls=PMGJSONEncoder)
    else:
        m = re.search("\.(pdb|mol|mdl|sdf|sd|ml2|sy2|mol2|cml|mrv)",
                      filename.lower())
        if m:
            return BabelMolAdaptor(mol).write_file(filename, m.group(1))

    raise ValueError("Unrecognized file extension!")
Beispiel #3
0
    def setUp(self):

        coords = [[0.000000, 0.000000, 0.000000],
                  [0.000000, 0.000000, 1.089000],
                  [1.026719, 0.000000, -0.363000],
                  [-0.513360, -0.889165, -0.363000],
                  [-0.513360, 0.889165, -0.363000]]
        self.coords = coords
        mol = Molecule(["C", "H", "H", "H", "H"], coords)
        self.gau = GaussianInput(
            mol, route_parameters={'SP': "", "SCF": "Tight"},
            input_parameters={"EPS": 12})