当前位置: 首页>>代码示例>>Python>>正文


Python structure.Molecule类代码示例

本文整理汇总了Python中pymatgen.core.structure.Molecule的典型用法代码示例。如果您正苦于以下问题:Python Molecule类的具体用法?Python Molecule怎么用?Python Molecule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Molecule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_assimilate_opt_with_hidden_changes_from_handler

 def test_assimilate_opt_with_hidden_changes_from_handler(self):
     drone = QChemDrone(additional_fields={"special_run_type": "frequency_flattener"})
     doc = drone.assimilate(
         path=os.path.join(module_dir, "..", "test_files", "1746_complete"),
         input_file="mol.qin",
         output_file="mol.qout",
         multirun=False)
     self.assertEqual(doc["input"]["job_type"], "opt")
     self.assertEqual(doc["output"]["job_type"], "freq")
     self.assertEqual(doc["output"]["final_energy"], -303.835532370106)
     self.assertEqual(doc["smiles"], "O1C(=CC1=O)[CH]")
     self.assertEqual(doc["state"], "successful")
     self.assertEqual(doc["num_frequencies_flattened"], 0)
     self.assertEqual(doc["walltime"], 631.54)
     self.assertEqual(doc["cputime"], 7471.17)
     self.assertEqual(doc["formula_pretty"], "HC2O")
     self.assertEqual(doc["formula_anonymous"], "ABC2")
     self.assertEqual(doc["chemsys"], "C-H-O")
     self.assertEqual(doc["pointgroup"], "C1")
     self.assertEqual(doc["orig"]["rem"], doc["calcs_reversed"][-1]["input"]["rem"])
     orig_molgraph = MoleculeGraph.with_local_env_strategy(Molecule.from_dict(doc["orig"]["molecule"]),
                                                           OpenBabelNN(),
                                                           reorder=False,
                                                           extend_structure=False)
     initial_molgraph = MoleculeGraph.with_local_env_strategy(Molecule.from_dict(doc["input"]["initial_molecule"]),
                                                              OpenBabelNN(),
                                                              reorder=False,
                                                              extend_structure=False)
     self.assertEqual(orig_molgraph.isomorphic_to(initial_molgraph), False)
开发者ID:montoyjh,项目名称:MatMethods,代码行数:29,代码来源:test_drones.py

示例2: test_get_bonds

    def test_get_bonds(self):
        mol1 = Molecule.from_file(os.path.join(test_dir, "t1.xyz"))
        msc = MoleculeStructureComparator()
        # noinspection PyProtectedMember
        bonds = msc._get_bonds(mol1)
        bonds_ref = [(0, 1), (0, 2), (0, 3), (0, 23), (3, 4), (3, 5), (5, 6),
                     (5, 7), (7, 8), (7, 9), (7, 21), (9, 10), (9, 11),
                     (9, 12), (12, 13), (12, 14), (12, 15), (15, 16), (15, 17),
                     (15, 18), (18, 19), (18, 20), (18, 21), (21, 22),
                     (21, 23), (23, 24), (23, 25)]
        self.assertEqual(bonds, bonds_ref)
        mol2 = Molecule.from_file(os.path.join(test_dir, "MgBH42.xyz"))
        bonds = msc._get_bonds(mol2)
        self.assertEqual(bonds, [(1, 3), (2, 3), (3, 4), (3, 5), (6, 8), (7, 8),
                                 (8, 9), (8, 10)])
        msc = MoleculeStructureComparator(ignore_ionic_bond=False)
        bonds = msc._get_bonds(mol2)
        self.assertEqual(bonds, [(0, 1), (0, 2), (0, 3), (0, 5), (0, 6), (0, 7),
                                 (0, 8), (0, 9), (1, 3), (2, 3), (3, 4), (3, 5),
                                 (6, 8), (7, 8), (8, 9), (8, 10)])

        mol1 = Molecule.from_file(os.path.join(test_dir, "molecule_with_halogen_bonds_1.xyz"))
        msc = MoleculeStructureComparator()
        # noinspection PyProtectedMember
        bonds = msc._get_bonds(mol1)
        self.assertEqual(bonds, [(0, 12), (0, 13), (0, 14), (0, 15), (1, 12), (1, 16),
                                 (1, 17), (1, 18), (2, 4), (2, 11), (2, 19), (3, 5),
                                 (3, 10), (3, 20), (4, 6), (4, 10), (5, 11), (5, 12),
                                 (6, 7), (6, 8), (6, 9)])
开发者ID:AtlasL,项目名称:pymatgen,代码行数:29,代码来源:test_molecule_structure_comparator.py

示例3: test_assimilate_unstable_opt

 def test_assimilate_unstable_opt(self):
     drone = QChemDrone(
         runs=[
             "opt_0", "freq_0", "opt_1", "freq_1", "opt_2", "freq_2",
             "opt_3", "freq_3"
         ],
         additional_fields={"special_run_type": "frequency_flattener"})
     doc = drone.assimilate(
         path=os.path.join(module_dir, "..", "test_files", "2620_complete"),
         input_file="mol.qin",
         output_file="mol.qout",
         multirun=False)
     self.assertEqual(doc["input"]["job_type"], "opt")
     self.assertEqual(doc["output"]["job_type"], "opt")
     self.assertEqual(doc["output"]["final_energy"], "unstable")
     self.assertEqual(doc["smiles"], "[S](=O)[N]S[C]")
     self.assertEqual(doc["state"], "unsuccessful")
     self.assertEqual(doc["num_frequencies_flattened"], 0)
     self.assertEqual(doc["walltime"], None)
     self.assertEqual(doc["cputime"], None)
     self.assertEqual(doc["formula_pretty"], "CS2NO")
     self.assertEqual(doc["formula_anonymous"], "ABCD2")
     self.assertEqual(doc["chemsys"], "C-N-O-S")
     self.assertEqual(doc["pointgroup"], "C1")
     self.assertEqual(doc["orig"]["rem"], doc["calcs_reversed"][-1]["input"]["rem"])
     self.assertEqual(doc["orig"]["molecule"], doc["calcs_reversed"][-1]["input"]["molecule"])
     orig_molgraph = MoleculeGraph.with_local_env_strategy(Molecule.from_dict(doc["orig"]["molecule"]),
                                                           OpenBabelNN(),
                                                           reorder=False,
                                                           extend_structure=False)
     initial_molgraph = MoleculeGraph.with_local_env_strategy(Molecule.from_dict(doc["input"]["initial_molecule"]),
                                                              OpenBabelNN(),
                                                              reorder=False,
                                                              extend_structure=False)
     self.assertEqual(orig_molgraph.isomorphic_to(initial_molgraph), True)
开发者ID:montoyjh,项目名称:MatMethods,代码行数:35,代码来源:test_drones.py

示例4: get_structures_from_trajectory

    def get_structures_from_trajectory(self):
        """
        Convert the coordinates in each time step to a structure(boxed molecule).
        Used to construct DiffusionAnalyzer object.

        Returns:
            list of Structure objects
        """
        structures = []
        mass_to_symbol = dict(
            (round(y["Atomic mass"], 1), x) for x, y in _pt_data.items())
        unique_atomic_masses = np.array(self.lammps_data.atomic_masses)[:, 1]
        for step in range(self.timesteps.size):
            begin = step * self.natoms
            end = (step + 1) * self.natoms
            mol_vector_structured = \
                self.trajectory[begin:end][:][["x", "y", "z"]]
            new_shape = mol_vector_structured.shape + (-1,)
            mol_vector = mol_vector_structured.view(np.float64).reshape(
                new_shape)
            coords = mol_vector.copy()
            species = [mass_to_symbol[round(unique_atomic_masses[atype - 1], 1)]
                       for atype in self.trajectory[begin:end][:]["atom_type"]]
            mol = Molecule(species, coords)
            try:
                boxed_mol = mol.get_boxed_structure(*self.box_lengths)
            except ValueError as error:
                print("Error: '{}' at timestep {} in the trajectory".format(
                    error,
                    int(self.timesteps[step])))
            structures.append(boxed_mol)
        return structures
开发者ID:adozier,项目名称:pymatgen,代码行数:32,代码来源:output.py

示例5: test_get_centered_molecule

 def test_get_centered_molecule(self):
     mol = Molecule(["O"] * 2, [[0, 0, 0], [0, 0, 1.2]],
                    spin_multiplicity=3)
     centered = mol.get_centered_molecule()
     self.assertFalse(np.allclose(mol.center_of_mass, np.zeros(3),
                                  atol=1e-7))
     self.assertTrue(np.allclose(centered.center_of_mass, np.zeros(3),
                                 atol=1e-7))
开发者ID:thuwangming,项目名称:pymatgen,代码行数:8,代码来源:test_structure.py

示例6: setUpClass

    def setUpClass(cls):
        polymer_chain = Molecule.from_file(os.path.join(test_dir, "polymer_chain.xyz"))
        polymer_linear = Molecule.from_file(os.path.join(test_dir, "polymer_linear.xyz"))
        cls.polymer_matrix = Molecule.from_file(os.path.join(test_dir, "polymer_matrix.xyz"))

        charges = [-0.1187, 0.0861, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861,
                   0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861,
                   0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861,
                   0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861,
                   0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861,
                   0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861,
                   0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.1187, 0.0861,
                   0.0861, 0.0861]
        polymer_linear.add_site_property("charge", charges)
        topology = Topology.from_molecule(polymer_linear)

        cls.polymer_linear_ff_decorated = Molecule.from_file(
            os.path.join(test_dir,"polymer_linear.xyz"))
        ff_map = ['C2', 'H3', 'H2', 'H3', 'O', 'C3', 'H2', 'H3', 'C2', 'H3',
                  'H2', 'O', 'C2', 'H3', 'H2', 'C3', 'H2', 'H3', 'O', 'C3',
                  'H2', 'H3', 'C2', 'H3', 'H2', 'O', 'C2', 'H3', 'H2', 'C3',
                  'H2', 'H3', 'O', 'C3', 'H2', 'H3', 'C2', 'H3', 'H2', 'O',
                  'C2', 'H3', 'H2', 'C3', 'H2', 'H3', 'O', 'C3', 'H2', 'H3', 'H2']
        cls.polymer_linear_ff_decorated.add_site_property("ff_map", ff_map)

        atoms = OrderedDict([("C", "C"), ("H", "H"), ("O", "O")])
        bonds = OrderedDict([((u'C', u'O'), [1000, 1.4115]),
                             ((u'C', u'H'), [1000, 1.1041]),
                             ((u'C', u'C'), [1000, 1.5075])])
        pairs = OrderedDict([((u'O', u'O'), [75844.8, 0.2461, 396.9]),
                             ((u'H', u'H'), [2649.6, 0.2674, 27.22]),
                             ((u'C', u'C'), [14976.0, 0.3236, 637.6])])
        angles = OrderedDict([((u'C', u'C', u'H'), [42.9, 110.1]),
                              ((u'H', u'C', u'H'), [38.5, 109.47]),
                              ((u'H', u'C', u'O'), [56.0, 109.48]),
                              ((u'C', u'C', u'O'), [86.0, 108.54]),
                              ((u'C', u'O', u'C'), [74.5, 108.05])])
        dihedrals = OrderedDict([((u'H', u'C', u'O', u'C'), [0.0, 0.0, -0.73, 0.0]),
                                 ((u'H', u'C', u'C', u'H'), [0.0, 0.0, 0.28, 0.0]),
                                 ((u'C', u'C', u'O', u'C'), [1.76, 0.67, 0.04, 0.0]),
                                 ((u'H', u'C', u'C', u'O'), [0.0, 0.0, 0.28, 0.0]),
                                 ((u'O', u'C', u'C', u'O'), [0.41, -2.1, -0.6, -0.82])])
        forcefield = ForceField(atoms, bonds, angles, dihedrals=dihedrals, pairs=pairs)

        cls.molecules = [polymer_chain] * 3
        cls.mols_number = [7, 3, 1]
        box_size = [[0.0, 50], [0.0, 50], [0.0, 50]]
        cls.topologies = [topology] * len(cls.molecules)

        cls.lammps_ff_data_1 = LammpsForceFieldData.from_forcefield_and_topology(
            cls.molecules, cls.mols_number, box_size, cls.polymer_matrix,
            forcefield, cls.topologies)
开发者ID:bocklund,项目名称:pymatgen,代码行数:52,代码来源:test_forcefield_data.py

示例7: test_are_equal

 def test_are_equal(self):
     msc1 = MoleculeStructureComparator()
     mol1 = Molecule.from_file(os.path.join(test_dir, "t1.xyz"))
     mol2 = Molecule.from_file(os.path.join(test_dir, "t2.xyz"))
     mol3 = Molecule.from_file(os.path.join(test_dir, "t3.xyz"))
     self.assertFalse(msc1.are_equal(mol1, mol2))
     self.assertTrue(msc1.are_equal(mol2, mol3))
     thio1 = Molecule.from_file(os.path.join(test_dir, "thiophene1.xyz"))
     thio2 = Molecule.from_file(os.path.join(test_dir, "thiophene2.xyz"))
     # noinspection PyProtectedMember
     msc2 = MoleculeStructureComparator(
         priority_bonds=msc1._get_bonds(thio1))
     self.assertTrue(msc2.are_equal(thio1, thio2))
开发者ID:antoinedewandre,项目名称:pymatgen,代码行数:13,代码来源:test_molecule_structure_comparator.py

示例8: setUpClass

 def setUpClass(cls):
     cls.pc = Molecule.from_file(
         os.path.join(test_dir, "PC.xyz"))
     cls.pos_pc = Molecule.from_file(
         os.path.join(test_dir, "PC.xyz"))
     cls.pos_pc.set_charge_and_spin(charge=1)
     cls.pc_edges = [[5, 10], [5, 12], [5, 11], [5, 3], [3, 7], [3, 4],
                     [3, 0], [4, 8], [4, 9], [4, 1], [6, 1], [6, 0], [6, 2]]
     cls.pc_frag1 = Molecule.from_file(
         os.path.join(test_dir, "PC_frag1.xyz"))
     cls.pc_frag1_edges = [[0, 2], [4, 2], [2, 1], [1, 3]]
     cls.tfsi = Molecule.from_file(os.path.join(test_dir, "TFSI.xyz"))
     cls.tfsi_edges = [14,1],[1,4],[1,5],[1,7],[7,11],[7,12],[7,13],[14,0],[0,2],[0,3],[0,6],[6,8],[6,9],[6,10]
开发者ID:ExpHP,项目名称:pymatgen,代码行数:13,代码来源:test_fragmenter.py

示例9: __init__

 def __init__(self, structure, rmax=15, 
              hkl_family=[(1, 0, 0), (1, 1, 1)],
              surface_energies=[28, 25] ):
     self.structure = structure
     self.rmax = rmax
     self.hkl_family = hkl_family
     self.surface_energies = surface_energies
     spherical_neighbors = self.structure.get_sites_in_sphere([0.0,0.0,0.0], self.rmax)
     recp_lattice = self.structure.lattice.reciprocal_lattice_crystallographic
     self.recp_lattice = recp_lattice.scale(1)
     self.set_miller_family()
     Molecule.__init__(self, [sn[0].species_and_occu for sn in spherical_neighbors],
                       [sn[0].coords for sn in spherical_neighbors], charge=0)
开发者ID:izxle,项目名称:MPInterfaces,代码行数:13,代码来源:nanoparticle.py

示例10: setUp

    def setUp(self):

        cyclohexene = Molecule.from_file(os.path.join(os.path.dirname(__file__), "..", "..", "..",
                                                      "test_files/graphs/cyclohexene.xyz"))
        self.cyclohexene = MoleculeGraph.with_empty_graph(cyclohexene,
                                                       edge_weight_name="strength",
                                                       edge_weight_units="")
        self.cyclohexene.add_edge(0, 1, weight=1.0)
        self.cyclohexene.add_edge(1, 2, weight=1.0)
        self.cyclohexene.add_edge(2, 3, weight=2.0)
        self.cyclohexene.add_edge(3, 4, weight=1.0)
        self.cyclohexene.add_edge(4, 5, weight=1.0)
        self.cyclohexene.add_edge(5, 0, weight=1.0)
        self.cyclohexene.add_edge(0, 6, weight=1.0)
        self.cyclohexene.add_edge(0, 7, weight=1.0)
        self.cyclohexene.add_edge(1, 8, weight=1.0)
        self.cyclohexene.add_edge(1, 9, weight=1.0)
        self.cyclohexene.add_edge(2, 10, weight=1.0)
        self.cyclohexene.add_edge(3, 11, weight=1.0)
        self.cyclohexene.add_edge(4, 12, weight=1.0)
        self.cyclohexene.add_edge(4, 13, weight=1.0)
        self.cyclohexene.add_edge(5, 14, weight=1.0)
        self.cyclohexene.add_edge(5, 15, weight=1.0)

        butadiene = Molecule.from_file(os.path.join(os.path.dirname(__file__), "..", "..", "..",
                                                    "test_files/graphs/butadiene.xyz"))
        self.butadiene = MoleculeGraph.with_empty_graph(butadiene,
                                                        edge_weight_name="strength",
                                                        edge_weight_units="")
        self.butadiene.add_edge(0, 1, weight=2.0)
        self.butadiene.add_edge(1, 2, weight=1.0)
        self.butadiene.add_edge(2, 3, weight=2.0)
        self.butadiene.add_edge(0, 4, weight=1.0)
        self.butadiene.add_edge(0, 5, weight=1.0)
        self.butadiene.add_edge(1, 6, weight=1.0)
        self.butadiene.add_edge(2, 7, weight=1.0)
        self.butadiene.add_edge(3, 8, weight=1.0)
        self.butadiene.add_edge(3, 9, weight=1.0)

        ethylene = Molecule.from_file(os.path.join(os.path.dirname(__file__), "..", "..", "..",
                                                   "test_files/graphs/ethylene.xyz"))
        self.ethylene = MoleculeGraph.with_empty_graph(ethylene,
                                                       edge_weight_name="strength",
                                                       edge_weight_units="")
        self.ethylene.add_edge(0, 1, weight=2.0)
        self.ethylene.add_edge(0, 2, weight=1.0)
        self.ethylene.add_edge(0, 3, weight=1.0)
        self.ethylene.add_edge(1, 4, weight=1.0)
        self.ethylene.add_edge(1, 5, weight=1.0)

        warnings.simplefilter("ignore")
开发者ID:albalu,项目名称:pymatgen,代码行数:51,代码来源:test_graphs.py

示例11: test_to_from_dict

 def test_to_from_dict(self):
     d = self.mol.as_dict()
     mol2 = IMolecule.from_dict(d)
     self.assertEqual(type(mol2), IMolecule)
     propertied_mol = Molecule(["C", "H", "H", "H", "H"], self.coords,
                               charge=1,
                               site_properties={'magmom':
                                                [0.5, -0.5, 1, 2, 3]})
     d = propertied_mol.as_dict()
     self.assertEqual(d['sites'][0]['properties']['magmom'], 0.5)
     mol = Molecule.from_dict(d)
     self.assertEqual(propertied_mol, mol)
     self.assertEqual(mol[0].magmom, 0.5)
     self.assertEqual(mol.formula, "H4 C1")
     self.assertEqual(mol.charge, 1)
开发者ID:Lightslayer,项目名称:pymatgen,代码行数:15,代码来源:test_structure.py

示例12: test_isomorphic_to

    def test_isomorphic_to(self):
        ethylene = Molecule.from_file(
            os.path.join(
                os.path.dirname(__file__),
                "..",
                "..",
                "..",
                "test_files/graphs/ethylene.xyz",
            )
        )
        # switch carbons
        ethylene[0], ethylene[1] = ethylene[1], ethylene[0]

        eth_copy = MoleculeGraph.with_edges(
            ethylene,
            {
                (0, 1): {"weight": 2},
                (1, 2): {"weight": 1},
                (1, 3): {"weight": 1},
                (0, 4): {"weight": 1},
                (0, 5): {"weight": 1},
            },
        )
        # If they are equal, they must also be isomorphic
        eth_copy = copy.deepcopy(self.ethylene)
        self.assertTrue(self.ethylene.isomorphic_to(eth_copy))
        self.assertFalse(self.butadiene.isomorphic_to(self.ethylene))
开发者ID:adengz,项目名称:pymatgen,代码行数:27,代码来源:test_graphs.py

示例13: from_dict

 def from_dict(cls, d):
     return FiestaInput(Molecule.from_dict(d["mol"]),
                        correlation_grid=d["correlation_grid"],
                        Exc_DFT_option=d["Exc_DFT_option"],
                        COHSEX_options=d["geometry_options"],
                        GW_options=d["symmetry_options"],
                        BSE_TDDFT_options=d["memory_options"])
开发者ID:albalu,项目名称:pymatgen,代码行数:7,代码来源:fiesta.py

示例14: setUp

    def setUp(self):
        self.polymer_linear = Molecule.from_file(
            os.path.join(test_dir, "polymer_linear.xyz"))

        charges = [-0.1187, 0.0861, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861,
                   0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861,
                   0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861,
                   0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861,
                   0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861,
                   0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861,
                   0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.1187, 0.0861,
                   0.0861, 0.0861]
        ff_map = ["C3", "H3", "H3", "H3", "O", "C2", "H2",
                   "H2", "C2", "H2", "H2", "O", "C2", "H2",
                   "H2", "C2", "H2", "H2", "O", "C2", "H2",
                   "H2", "C2", "H2", "H2", "O", "C2", "H2",
                   "H2", "C2", "H2", "H2", "O", "C2", "H2",
                   "H2", "C2", "H2", "H2", "O", "C2", "H2",
                   "H2", "C2", "H2", "H2", "O", "C3", "H3", "H3", "H3"]
        self.polymer_linear.add_site_property("charge", charges)
        self.polymer_linear.add_site_property("ff_map", ff_map)
        self.topology = Topology.from_molecule(self.polymer_linear)
        self.forcefield = ForceField.from_file(
            os.path.join(test_dir, "ffmap_data.yaml"))

        box_size = [[0.0, 50],
                    [0.0, 50],
                    [0.0, 50]]
        self.lammps_ff_data = LammpsForceFieldData.from_forcefield_and_topology(
            [self.polymer_linear], [1], box_size, self.polymer_linear,
            self.forcefield, [self.topology])
开发者ID:matk86,项目名称:pymatgen,代码行数:31,代码来源:test_topology_forcefield.py

示例15: setUp

 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.mol = Molecule(["C", "H", "H", "H", "H"], coords)
开发者ID:Lightslayer,项目名称:pymatgen,代码行数:7,代码来源:test_structure.py


注:本文中的pymatgen.core.structure.Molecule类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。