def test_atom_mapping(): """ This is a test for the corner case where atom mapping for `LiF2 -> Li+ + F2` was incorrect due to reordering of reactant subgraphs. It is fixed and the test should pass now. """ test_file = os.path.join( os.path.dirname(__file__), "..", "..", "test_files", "reaction_files", "LiF2_to_Li_F2.json", ) entries = loadfn(test_file) bucketed_entries = bucket_mol_entries(entries) reactions = CoordinationBondChangeReaction.generate(bucketed_entries) assert len(reactions) == 1 rxn = reactions[0] assert rxn.reactant_atom_mapping == [{0: 0, 1: 1, 2: 2}] assert rxn.product_atom_mapping == [{0: 1, 1: 2}, {0: 0}]
def test_atom_mapping(self): entries = bucket_mol_entries( [self.LiEC_entry, self.EC_minus_entry, self.Li_entry]) reactions, families = CoordinationBondChangeReaction.generate(entries) self.assertEqual(len(reactions), 1) rxn = reactions[0] self.assertEqual(rxn.reactant_ids[0], self.LiEC_entry.entry_id) self.assertEqual(rxn.product_ids[0], self.EC_minus_entry.entry_id) self.assertEqual(rxn.product_ids[1], self.Li_entry.entry_id) self.assertEqual( rxn.reactants_atom_mapping, [{ 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10 }], ) self.assertEqual( rxn.products_atom_mapping, [{ 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 7, 7: 8, 8: 9, 9: 10 }, { 0: 6 }], )
def test_atom_mapping(self): ents = bucket_mol_entries( [entries["LiEC"], entries["EC_-1"], entries["Li"]]) reactions = CoordinationBondChangeReaction.generate(ents) self.assertEqual(len(reactions), 1) rxn = reactions[0] self.assertEqual(rxn.reactant.entry_id, entries["LiEC"].entry_id) self.assertEqual(rxn.product_0.entry_id, entries["EC_-1"].entry_id) self.assertEqual(rxn.product_1.entry_id, entries["Li"].entry_id) self.assertEqual( rxn.reactant_atom_mapping, [{ 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10 }], ) self.assertEqual( rxn.product_atom_mapping, [{ 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 7, 7: 8, 8: 9, 9: 10 }, { 0: 6 }], )
def test_atom_mapping(self): entries = bucket_mol_entries( [self.LiEC_RO_entry, self.C1Li1O3_entry, self.C2H4_entry]) reactions, families = IntermolecularReaction.generate(entries) self.assertEqual(len(reactions), 1) rxn = reactions[0] self.assertEqual(rxn.reactant_ids[0], self.LiEC_RO_entry.entry_id) self.assertEqual(rxn.product_ids[0], self.C2H4_entry.entry_id) self.assertEqual(rxn.product_ids[1], self.C1Li1O3_entry.entry_id) self.assertEqual( rxn.reactants_atom_mapping, [{ 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10 }], ) self.assertEqual( rxn.products_atom_mapping, [{ 0: 0, 1: 1, 2: 7, 3: 8, 4: 9, 5: 10 }, { 0: 2, 1: 3, 2: 4, 3: 5, 4: 6 }], )
def test_atom_mapping(self): ents = bucket_mol_entries( [entries["LiEC_RO"], entries["C1Li1O3"], entries["C2H4"]]) reactions = IntermolecularReaction.generate(ents) self.assertEqual(len(reactions), 1) rxn = reactions[0] self.assertEqual(rxn.reactant.entry_id, entries["LiEC_RO"].entry_id) self.assertEqual(rxn.product_0.entry_id, entries["C2H4"].entry_id) self.assertEqual(rxn.product_1.entry_id, entries["C1Li1O3"].entry_id) self.assertEqual( rxn.reactant_atom_mapping, [{ 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10 }], ) self.assertEqual( rxn.product_atom_mapping, [{ 0: 0, 1: 1, 2: 7, 3: 8, 4: 9, 5: 10 }, { 0: 2, 1: 3, 2: 4, 3: 5, 4: 6 }], )
def test_atom_mapping(self): ents = bucket_mol_entries([entries["LiEC_RO"], entries["LiEC"]]) reactions = IntramolSingleBondChangeReaction.generate(ents) self.assertEqual(len(reactions), 1) rxn = reactions[0] self.assertEqual(rxn.reactant.entry_id, entries["LiEC_RO"].entry_id) self.assertEqual(rxn.product.entry_id, entries["LiEC"].entry_id) self.assertEqual( rxn.reactants_atom_mapping, [{ 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10 }], ) self.assertEqual( rxn.products_atom_mapping, [{ 0: 2, 1: 3, 2: 1, 3: 4, 4: 5, 5: 0, 6: 6, 7: 9, 8: 10, 9: 7, 10: 8 }], )
def test_bucket_mol_entries(): C2H4_entry = MoleculeEntry( Molecule.from_file(os.path.join(test_dir, "C2H4.xyz")), energy=0.0, enthalpy=0.0, entropy=0.0, ) LiEC_RO_entry = MoleculeEntry( Molecule.from_file(os.path.join(test_dir, "LiEC_RO.xyz")), energy=0.0, enthalpy=0.0, entropy=0.0, ) C1Li1O3_entry = MoleculeEntry( Molecule.from_file(os.path.join(test_dir, "C1Li1O3.xyz")), energy=0.0, enthalpy=0.0, entropy=0.0, ) bucket = bucket_mol_entries([C2H4_entry, LiEC_RO_entry, C1Li1O3_entry]) ref_dict = { "C2 H4": { 5: { 0: [C2H4_entry] } }, "C3 H4 Li1 O3": { 11: { 0: [LiEC_RO_entry] } }, "C1 Li1 O3": { 5: { 0: [C1Li1O3_entry] } }, } assert bucket == ref_dict
def test_atom_mapping(self): entries = bucket_mol_entries( [self.EC_minus_entry, self.EC_0_entry, self.EC_1_entry]) reactions, families = RedoxReaction.generate(entries) self.assertEqual(len(reactions), 2) for r in reactions: self.assertEqual( r.reactants_atom_mapping, [{ 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9 }], ) self.assertEqual( r.products_atom_mapping, [{ 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9 }], )
def test_atom_mapping(self): ents = bucket_mol_entries( [entries["EC_-1"], entries["EC_0"], entries["EC_1"]]) reactions = RedoxReaction.generate(ents) self.assertEqual(len(reactions), 2) for r in reactions: self.assertEqual( r.reactants_atom_mapping, [{ 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9 }], ) self.assertEqual( r.products_atom_mapping, [{ 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9 }], )