Esempio n. 1
0
 def test_spherical(self):
     a = PointGroupAnalyzer(CH4)
     self.assertEqual(a.sch_symbol, "Td")
     self.assertEqual(len(a.get_pointgroup()), 24)
     a = PointGroupAnalyzer(PF6)
     self.assertEqual(a.sch_symbol, "Oh")
     self.assertEqual(len(a.get_pointgroup()), 48)
     xyz = XYZ.from_file(os.path.join(test_dir, "c60.xyz"))
     a = PointGroupAnalyzer(xyz.molecule)
     self.assertEqual(a.sch_symbol, "Ih")
Esempio n. 2
0
 def test_dihedral(self):
     a = PointGroupAnalyzer(C2H4)
     self.assertEqual(a.sch_symbol, "D2h")
     self.assertEqual(len(a.get_pointgroup()), 8)
     a = PointGroupAnalyzer(BF3)
     self.assertEqual(a.sch_symbol, "D3h")
     self.assertEqual(len(a.get_pointgroup()), 12)
     xyz = XYZ.from_file(os.path.join(test_dir, "b12h12.xyz"))
     a = PointGroupAnalyzer(xyz.molecule)
     self.assertEqual(a.sch_symbol, "D5d")
Esempio n. 3
0
 def test_spherical(self):
     a = PointGroupAnalyzer(CH4)
     self.assertEqual(a.sch_symbol, "Td")
     self.assertEqual(len(a.get_pointgroup()), 24)
     a = PointGroupAnalyzer(PF6)
     self.assertEqual(a.sch_symbol, "Oh")
     self.assertEqual(len(a.get_pointgroup()), 48)
     xyz = XYZ.from_file(os.path.join(test_dir, "c60.xyz"))
     a = PointGroupAnalyzer(xyz.molecule)
     self.assertEqual(a.sch_symbol, "Ih")
Esempio n. 4
0
 def test_dihedral(self):
     a = PointGroupAnalyzer(C2H4)
     self.assertEqual(a.sch_symbol, "D2h")
     self.assertEqual(len(a.get_pointgroup()), 8)
     a = PointGroupAnalyzer(BF3)
     self.assertEqual(a.sch_symbol, "D3h")
     self.assertEqual(len(a.get_pointgroup()), 12)
     xyz = XYZ.from_file(os.path.join(test_dir, "b12h12.xyz"))
     a = PointGroupAnalyzer(xyz.molecule)
     self.assertEqual(a.sch_symbol, "D5d")
Esempio n. 5
0
def read_mol(filename):
    """
    Reads a molecule 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), Gaussian output (.out|and
    pymatgen's JSON serialized molecules. Using openbabel,
    many more extensions are supported but requires openbabel to be installed.

    Args:
        filename:
            A filename to read from.

    Returns:
        A Molecule object.
    """
    fname = os.path.basename(filename)
    if fnmatch(fname.lower(), "*.xyz*"):
        return XYZ.from_file(filename).molecule
    elif any([
            fnmatch(fname.lower(), "*.{}*".format(r))
            for r in ["gjf", "g03", "g09", "com", "inp"]
    ]):
        return GaussianInput.from_file(filename).molecule
    elif any([
            fnmatch(fname.lower(), "*.{}*".format(r))
            for r in ["out", "lis", "log"]
    ]):
        return GaussianOutput(filename).final_structure
    elif fnmatch(fname, "*.json*") or fnmatch(fname, "*.mson*"):
        with zopen(filename) as f:
            s = json.load(f, cls=PMGJSONDecoder)
            if type(s) != Molecule:
                raise IOError("File does not contain a valid serialized "
                              "molecule")
            return s
    else:
        m = re.search("\.(pdb|mol|mdl|sdf|sd|ml2|sy2|mol2|cml|mrv)",
                      filename.lower())
        if m:
            return BabelMolAdaptor.from_file(filename, m.group(1)).pymatgen_mol

    raise ValueError("Unrecognized file extension!")
Esempio n. 6
0
def read_mol(filename):
    """
    Reads a molecule 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), Gaussian output (.out|and
    pymatgen's JSON serialized molecules. Using openbabel,
    many more extensions are supported but requires openbabel to be installed.

    Args:
        filename:
            A filename to read from.

    Returns:
        A Molecule object.
    """
    fname = os.path.basename(filename)
    if fnmatch(fname.lower(), "*.xyz*"):
        return XYZ.from_file(filename).molecule
    elif any([fnmatch(fname.lower(), "*.{}*".format(r))
              for r in ["gjf", "g03", "g09", "com", "inp"]]):
        return GaussianInput.from_file(filename).molecule
    elif any([fnmatch(fname.lower(), "*.{}*".format(r))
              for r in ["out", "lis", "log"]]):
        return GaussianOutput(filename).final_structure
    elif fnmatch(fname, "*.json*") or fnmatch(fname, "*.mson*"):
        with zopen(filename) as f:
            s = json.load(f, cls=PMGJSONDecoder)
            if type(s) != Molecule:
                raise IOError("File does not contain a valid serialized "
                              "molecule")
            return s
    else:
        m = re.search("\.(pdb|mol|mdl|sdf|sd|ml2|sy2|mol2|cml|mrv)",
                      filename.lower())
        if m:
            return BabelMolAdaptor.from_file(filename,
                                             m.group(1)).pymatgen_mol

    raise ValueError("Unrecognized file extension!")