def test_free_energy(self): reaction = CoordinationBondChangeReaction( self.LiEC_entry, [self.EC_minus_entry, self.Li_entry]) reaction.free_energy() self.assertEqual(reaction.free_energy_A, 1.857340187929367) self.assertEqual(reaction.free_energy_B, -1.857340187929367)
def test_energy(self): reaction = CoordinationBondChangeReaction( self.LiEC_entry, [self.EC_minus_entry, self.Li_entry]) reaction.energy() self.assertEqual(reaction.energy_A, 0.08317397598398202) self.assertEqual(reaction.energy_B, -0.08317397598398202)
def test_free_energy(self): reaction = CoordinationBondChangeReaction( entries["LiEC"], [entries["EC_-1"], entries["Li"]]) reaction.set_free_energy() self.assertEqual(reaction.free_energy_A, 1.857340187929367) self.assertEqual(reaction.free_energy_B, -1.8573401879297649)
def test_graph_representation(self): # set up RN RN = ReactionNetwork.from_input_entries(self.LiEC_reextended_entries) # set up input variables LiEC_ind = None EC_minus_ind = None Li_ind = None LiEC_RN_entry = None EC_minus_RN_entry = None Li_RN_entry = None for entry in RN.entries["C3 H4 Li1 O3"][12][0]: if self.LiEC_mg.isomorphic_to(entry.mol_graph): LiEC_ind = entry.parameters["ind"] LiEC_RN_entry = entry break for entry in RN.entries["C3 H4 O3"][10][-1]: if self.EC_mg.isomorphic_to(entry.mol_graph): EC_minus_ind = entry.parameters["ind"] EC_minus_RN_entry = entry break for entry in RN.entries["Li1"][0][1]: Li_ind = entry.parameters["ind"] Li_RN_entry = entry break # perform calc reaction = CoordinationBondChangeReaction( LiEC_RN_entry, [EC_minus_RN_entry, Li_RN_entry]) graph = reaction.graph_representation() # assert self.assertCountEqual( list(graph.nodes), [ LiEC_ind, EC_minus_ind, Li_ind, str(LiEC_ind) + "," + str(EC_minus_ind) + "+" + str(Li_ind), str(EC_minus_ind) + "+PR_" + str(Li_ind) + "," + str(LiEC_ind), str(Li_ind) + "+PR_" + str(EC_minus_ind) + "," + str(LiEC_ind), ], ) self.assertEqual(len(graph.edges), 7) self.assertEqual( graph.get_edge_data( LiEC_ind, str(LiEC_ind) + "," + str(EC_minus_ind) + "+" + str(Li_ind))["softplus"], 1.5036425808336291, ) self.assertEqual( graph.get_edge_data( LiEC_ind, str(Li_ind) + "+PR_" + str(EC_minus_ind) + "," + str(LiEC_ind)), None, )
def test_generate(self): reactions = CoordinationBondChangeReaction.generate( entries["RN"].entries) self.assertEqual(len(reactions), 48) reaction_set = set() for reaction in reactions: reaction_set.add( frozenset([ reaction.reactant.entry_id, reaction.product_0.entry_id, reaction.product_1.entry_id, ])) self.assertEqual(len(reaction_set), 48) for r in reactions: if r.reactant.entry_id == entries["LiEC"].entry_id: if (r.products[0].entry_id == entries["Li"].entry_id or r.products[1].entry_id == entries["Li"].entry_id): self.assertTrue( r.products[0].entry_id == entries["EC_-1"].entry_id or r.products[1].entry_id == entries["EC_-1"].entry_id) self.assertTrue(r.products[0].get_free_energy() == entries["EC_-1"].get_free_energy() or r.products[1].get_free_energy() == entries["EC_-1"].get_free_energy())
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_reaction_type(self): reaction = CoordinationBondChangeReaction( self.LiEC_entry, [self.EC_minus_entry, self.Li_entry]) self.assertEqual(reaction.rxn_type_A, "Coordination bond breaking AM -> A+M") self.assertEqual(reaction.rxn_type_B, "Coordination bond forming A+M -> AM")
def test_reaction_type(self): reaction = CoordinationBondChangeReaction( entries["LiEC"], [entries["EC_-1"], entries["Li"]]) self.assertEqual(reaction.__class__.__name__, "CoordinationBondChangeReaction") self.assertEqual(reaction.rxn_type_A, "Coordination bond breaking AM -> A+M") self.assertEqual(reaction.rxn_type_B, "Coordination bond forming A+M -> AM")
def test_graph_representation(self): # set up input variables LiEC_RN_entry = entries["LiEC"] EC_minus_RN_entry = entries["EC_-1"] Li_RN_entry = entries["Li"] LiEC_ind = LiEC_RN_entry.parameters["ind"] EC_minus_ind = EC_minus_RN_entry.parameters["ind"] Li_ind = Li_RN_entry.parameters["ind"] # perform calc reaction = CoordinationBondChangeReaction( LiEC_RN_entry, [EC_minus_RN_entry, Li_RN_entry]) graph = reaction.graph_representation() # assert self.assertCountEqual( list(graph.nodes), [ LiEC_ind, EC_minus_ind, Li_ind, str(LiEC_ind) + "," + str(EC_minus_ind) + "+" + str(Li_ind), str(EC_minus_ind) + "+PR_" + str(Li_ind) + "," + str(LiEC_ind), str(Li_ind) + "+PR_" + str(EC_minus_ind) + "," + str(LiEC_ind), ], ) self.assertEqual(len(graph.edges), 7) self.assertEqual( graph.get_edge_data( LiEC_ind, str(LiEC_ind) + "," + str(EC_minus_ind) + "+" + str(Li_ind))["softplus"], 1.5036425808336291, ) self.assertEqual( graph.get_edge_data( LiEC_ind, str(Li_ind) + "+PR_" + str(EC_minus_ind) + "," + str(LiEC_ind)), None, )
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_generate(self): reactions = CoordinationBondChangeReaction.generate( entries["RN"].entries) self.assertEqual(len(reactions), 50) for r in reactions: if r.reactant.entry_id == entries["LiEC"].entry_id: if (r.products[0].entry_id == entries["Li"].entry_id or r.products[1].entry_id == entries["Li"].entry_id): self.assertTrue( r.products[0].entry_id == entries["EC_-1"].entry_id or r.products[1].entry_id == entries["EC_-1"].entry_id) self.assertTrue(r.products[0].get_free_energy() == entries["EC_-1"].get_free_energy() or r.products[1].get_free_energy() == entries["EC_-1"].get_free_energy())
def test_generate(self): RN = ReactionNetwork.from_input_entries(self.LiEC_reextended_entries) reactions, families = CoordinationBondChangeReaction.generate( RN.entries) self.assertEqual(len(reactions), 50)
def test_energy(self): reaction = CoordinationBondChangeReaction( entries["LiEC"], [entries["EC_-1"], entries["Li"]]) self.assertEqual(reaction.energy_A, 0.08317397598398202) self.assertEqual(reaction.energy_B, -0.08317397598399001)