def test_getting_equivalence_from_two_stage_resp_ivary(self) -> None: # MeSO4 [S O O (bridging) O C H H H] ivary1 = Respin.Ivary([0, 0, 0, 2, 2, 0, 0, 0, 0]) ivary2 = Respin.Ivary([-1, -1, -1, -1, -1, 0, 0, 7, 7]) equivalence = get_equivalence_from_two_stage_resp_ivary(ivary1, ivary2) expected = Equivalence([None, None, None, 1, 1, None, None, 6, 6]) self.assertListEqual(equivalence.values, expected.values)
def setUp(self) -> None: super().setUp() self.kwargs = { "esp_data": self.esp_data, "equivalence": Equivalence([None, None, 1, 1, 1]), "molecule": Molecule([Atom(atomic_number) for atomic_number in [6, 1, 1, 1, 1]]), "frozen_atoms": [0, 2, 4], "total_charge": 0, "initial_charges": [Charge(x) for x in [-0.5, 0, 0, 0, 0]] }
def test_equivalencing(self) -> None: charges = fit_with_equivalencing( esp_data=self.esp_data, equivalence=Equivalence([None, None, 1, 1, 1]), molecule=Molecule([Atom(atomic_number) for atomic_number in [6, 1, 1, 1, 1]]), total_charge=0 ) self.assertListsAlmostEqual( charges, # Expected values from resp calculations done a while back [-0.500040, 0.125010, 0.125010, 0.125010, 0.125010] )
def _get_equivalence_from_ivary(ivary: Respin.Ivary) -> Equivalence: """Get atom equivalence information from an `Respin.Ivary` object This function is private as users probably mean to use the `get_equivalence` function instead. `Ivary` objects are specific to ``resp`` program input and thus may not provide information about atom equivalence. The "respin" file may have been generated to perform any custom fitting with ``resp``. Only use this function when you're certain that the "respin" file contains all the equivalence information that you need. """ return Equivalence([ None if ivary_value == 0 else ivary_value - 1 for ivary_value in ivary.values ])
def test_hydrogen_fitting(self) -> None: charges = fit_hydrogens_only( esp_data=self.esp_data, equivalence=Equivalence([None, None, 1, 1, 1]), molecule=Molecule([Atom(atomic_number) for atomic_number in [6, 1, 1, 1, 1]]), total_charge=0, initial_charges=[Charge(x) for x in [-0.5, 0, 0, 0, 0]] ) self.assertListsAlmostEqual( charges, # Expected values of hydrogen to share 0.5 e equally between them # to preserve total charge and net neutral charge. [-0.5, 0.125, 0.125, 0.125, 0.125] )
def test_fitting_with_frozen_atoms(self) -> None: respin = Respin( title= "Respin file prepared by `repESP` to perform fitting with selected atom charges frozen.", cntrl=Respin.Cntrl(iqopt=2, ihfree=0, qwt=0.0), subtitle="Resp charges for organic molecule", charge=0, molecule=Molecule( [Atom(atomic_number) for atomic_number in [6, 1, 1, 1, 1]]), ivary=Respin.Ivary([-1, 0, 2, -1, 2])) generated = prepare_respin(respin_generator=FrozenAtomsRespinGenerator( Equivalence([None, None, 1, 1, 1]), frozen_atoms=[0, 3]), total_charge=0, molecule=respin.molecule) self.assertAlmostEqualRecursive(respin, generated)
def test_equivalencing(self) -> None: respin = Respin( title= "Respin file prepared by `repESP` to perform atom equivalencing.", cntrl=Respin.Cntrl(ihfree=0, qwt=0.0), subtitle="Resp charges for organic molecule", charge=0, molecule=Molecule( [Atom(atomic_number) for atomic_number in [6, 1, 1, 1, 1]]), ivary=Respin.Ivary([0, 0, 2, 2, 2])) generated = prepare_respin( respin_generator=EquivalenceOnlyRespinGenerator( Equivalence([None, None, 1, 1, 1])), total_charge=0, molecule=respin.molecule) self.assertAlmostEqualRecursive(respin, generated)
def test_fitting_hydrogens_only(self) -> None: respin = Respin( title= "Respin file prepared by `repESP` to perform fitting of hydrogen atoms.", cntrl=Respin.Cntrl(iqopt=2, ihfree=0, qwt=0.0), subtitle="Resp charges for organic molecule", charge=0, molecule=Molecule( [Atom(atomic_number) for atomic_number in [6, 1, 1, 1, 1]]), ivary=Respin.Ivary([-1, 0, 2, 2, 2])) generated = prepare_respin( respin_generator=FitHydrogensOnlyRespinGenerator( Equivalence([None, None, 1, 1, 1]), respin.molecule), total_charge=0, molecule=respin.molecule) self.assertAlmostEqualRecursive(respin, generated)
def test_ivary_from_equivalence(self) -> None: self.assertListEqual( Respin.Ivary([0, 0, 1, 2, 2]).values, Respin.Ivary.from_equivalence(Equivalence([None, None, 0, 1, 1])).values)
def setUp(self) -> None: # acetate anion [C O O C H H H] self.equivalence = Equivalence([None, None, 1, None, None, 4, 4]) self.methyl_methylene_mask = [ False, False, False, True, True, True, True ]
def test_cyclic_euqivalence(self) -> None: # It may be later decided that this should fail Equivalence validation # but until it does, functions in the library should cope with it. equivalence = Equivalence([5, 0, 1, 2, 3, 4]) result = average(self.charges, equivalence) self.assertListsAlmostEqual([3.5] * 6, result)
def test_typical_euqivalence(self) -> None: equivalence = Equivalence([None, None, 0, 1, 0, 1]) result = average(self.charges, equivalence) self.assertListsAlmostEqual([3, 4, 3, 4, 3, 4], result)
def test_basic_equivalence(self) -> None: equivalence = Equivalence([None, 0] + [None] * 4) result = average(self.charges, equivalence) self.assertListsAlmostEqual([1.5, 1.5, 3, 4, 5, 6], result)
def test_no_equivalence(self) -> None: equivalence = Equivalence([None] * 6) result = average(self.charges, equivalence) self.assertListsAlmostEqual(self.charges, result)