Ejemplo n.º 1
0
    def test_get_reaction_template(self):
        rct = MoleculeGraph.with_local_env_strategy(
            Molecule.from_file(
                (test_dir / "reactions" / "da" / "rct.xyz").as_posix()),
            CovalentBondNN())
        pro = MoleculeGraph.with_local_env_strategy(
            Molecule.from_file(
                (test_dir / "reactions" / "da" / "pro.xyz").as_posix()),
            CovalentBondNN())

        rg = get_reaction_graphs(rct,
                                 pro,
                                 allowed_form=2,
                                 allowed_break=0,
                                 stop_at_one=True)[0]

        template_0 = get_reaction_template(rg)
        self.assertSetEqual(set(template_0.nodes), {2, 5, 11, 12})
        self.assertEqual(len(template_0.edges), 3)
        template_1 = get_reaction_template(rg, order=1)
        self.assertSetEqual(set(template_1.nodes),
                            {0, 2, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16})
        self.assertEqual(len(template_1.edges), 14)
        template_2 = get_reaction_template(rg, order=2)
        self.assertSetEqual(
            set(template_2.nodes),
            {0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18})
        self.assertEqual(len(template_2.edges), 20)
        template_3 = get_reaction_template(rg, order=3)
        self.assertSetEqual(
            set(template_3.nodes),
            {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18})
        self.assertEqual(len(template_3.edges), 21)
Ejemplo n.º 2
0
    def test_bonded_structure(self):
        strat = CovalentBondNN()

        benzene = strat.get_bonded_structure(self.benzene)
        self.assertEqual(len(benzene.find_rings()), 1)

        acetylene = strat.get_bonded_structure(self.acetylene)
        self.assertEqual(len(acetylene.graph.nodes), 4)
Ejemplo n.º 3
0
    def test_get_atom_mappings(self):

        rct = MoleculeGraph.with_local_env_strategy(
            Molecule.from_file(
                (test_dir / "reactions" / "da" / "rct.xyz").as_posix()),
            CovalentBondNN())
        pro = MoleculeGraph.with_local_env_strategy(
            Molecule.from_file(
                (test_dir / "reactions" / "da" / "pro.xyz").as_posix()),
            CovalentBondNN())

        # Test with no valid mapping
        mapping = get_atom_mappings(rct, pro, allowed_form=1, allowed_break=0)
        self.assertEqual(len(mapping), 0)

        # Test with stop_at_one
        mapping = get_atom_mappings(rct, pro, allowed_form=2, allowed_break=0)
        self.assertEqual(len(mapping), 1)

        # Test without stop_at_one
        mapping = get_atom_mappings(rct,
                                    pro,
                                    allowed_form=2,
                                    allowed_break=0,
                                    stop_at_one=False)
        self.assertEqual(len(mapping), 4)

        # Test with give_best
        mapping = get_atom_mappings(rct,
                                    pro,
                                    allowed_form=2,
                                    allowed_break=0,
                                    stop_at_one=False,
                                    give_best=True)
        self.assertEqual(len(mapping), 1)
        self.assertDictEqual(
            mapping[0], {
                2: 0,
                5: 1,
                11: 2,
                0: 3,
                12: 4,
                4: 5,
                10: 6,
                13: 7,
                1: 8,
                3: 9,
                14: 10,
                6: 11,
                8: 12,
                9: 13,
                15: 14,
                16: 15,
                17: 16,
                7: 17,
                18: 18
            })
Ejemplo n.º 4
0
    def test_nn_orders(self):
        strat = CovalentBondNN()

        acetylene = strat.get_nn_info(self.acetylene, 0)
        self.assertEqual(acetylene[0]["weight"], 3)
        self.assertEqual(acetylene[1]["weight"], 1)

        benzene = strat.get_nn_info(self.benzene, 0)
        self.assertAlmostEqual(benzene[0]["weight"], 1.6596, places=4)
Ejemplo n.º 5
0
    def test_nn_orders(self):
        strat = CovalentBondNN()

        acetylene = strat.get_nn_info(self.acetylene, 0)
        self.assertEqual(acetylene[0]["weight"], 3)
        self.assertEqual(acetylene[1]["weight"], 1)

        benzene = strat.get_nn_info(self.benzene, 0)
        self.assertAlmostEqual(benzene[0]["weight"], 1.6596, places=4)
Ejemplo n.º 6
0
    def test_nn_length(self):
        strat = CovalentBondNN(order=False)

        benzene_bonds = strat.get_nn_info(self.benzene, 0)

        c_bonds = [b for b in benzene_bonds if str(b["site"].specie) == "C"]
        h_bonds = [b for b in benzene_bonds if str(b["site"].specie) == "H"]

        self.assertAlmostEqual(c_bonds[0]["weight"], 1.41, 2)
        self.assertAlmostEqual(h_bonds[0]["weight"], 1.02, 2)

        acetylene = strat.get_nn_info(self.acetylene, 0)
        self.assertAlmostEqual(acetylene[0]["weight"], 1.19, places=2)
Ejemplo n.º 7
0
    def test_nn_length(self):
        strat = CovalentBondNN(order=False)

        benzene_bonds = strat.get_nn_info(self.benzene, 0)

        c_bonds = [b for b in benzene_bonds if str(b["site"].specie) == "C"]
        h_bonds = [b for b in benzene_bonds if str(b["site"].specie) == "H"]

        self.assertAlmostEqual(c_bonds[0]["weight"], 1.41, 2)
        self.assertAlmostEqual(h_bonds[0]["weight"], 1.02, 2)

        acetylene = strat.get_nn_info(self.acetylene, 0)
        self.assertAlmostEqual(acetylene[0]["weight"], 1.19, places=2)
Ejemplo n.º 8
0
 def test_inappropriate_construction(self):
     # Check inappropriate strategy
     with self.assertRaises(ValueError):
         StructureGraph.with_local_env_strategy(self.NiO, CovalentBondNN())
Ejemplo n.º 9
0
def get_NNs_pm(atoms, site_idx, NN_method):
    """
	Get coordinating atoms to the adsorption site

	Args:
		atoms (Atoms object): atoms object of MOF

		site_idx (int): ASE index of adsorption site
		
		NN_method (string): string representing the desired Pymatgen
		nearest neighbor algorithm:
		refer to http://pymatgen.org/_modules/pymatgen/analysis/local_env.html
	
	Returns:
		neighbors_idx (list of ints): ASE indices of coordinating atoms
	"""
    #Convert ASE Atoms object to Pymatgen Structure object
    bridge = pm_ase.AseAtomsAdaptor()
    struct = bridge.get_structure(atoms)

    #Select Pymatgen NN algorithm
    NN_method = NN_method.lower()
    if NN_method == 'vire':
        nn_object = MinimumVIRENN()
    elif NN_method == 'voronoi':
        nn_object = VoronoiNN()
    elif NN_method == 'jmol':
        nn_object = JmolNN()
    elif NN_method == 'min_dist':
        nn_object = MinimumDistanceNN()
    elif NN_method == 'okeeffe':
        nn_object = MinimumOKeeffeNN()
    elif NN_method == 'brunner_real':
        nn_object = BrunnerNN_real()
    elif NN_method == 'brunner_recpirocal':
        nn_object = BrunnerNN_reciprocal()
    elif NN_method == 'brunner_relative':
        nn_object = BrunnerNN_relative()
    elif NN_method == 'econ':
        nn_object = EconNN()
    elif NN_method == 'dict':
        #requires a cutoff dictionary located in the pwd
        nn_object = CutOffDictNN(cut_off_dict='cut_off_dict.txt')
    elif NN_method == 'critic2':
        nn_object = Critic2NN()
    elif NN_method == 'openbabel':
        nn_object = OpenBabelNN()
    elif NN_method == 'covalent':
        nn_object = CovalentBondNN()
    elif NN_method == 'crystal':
        nn_object = CrystalNN(porous_adjustment=True)
    elif NN_method == 'crystal_nonporous':
        nn_object = CrystalNN(porous_adjustment=False)
    else:
        raise ValueError('Invalid NN algorithm specified')

    #Find coordinating atoms
    with warnings.catch_warnings():
        warnings.simplefilter('ignore')
        neighbors = nn_object.get_nn_info(struct, site_idx)
    neighbors_idx = []
    for neighbor in neighbors:
        neighbors_idx.append(neighbor['site_index'])

    return neighbors_idx