def test_add_to_cache(tmp_amine2): mmff = stk.MMFF(use_cache=True) mmff_energy = stk.MMFFEnergy() init_energy = mmff_energy.get_energy(tmp_amine2) mmff.add_to_cache(tmp_amine2) mmff.optimize(tmp_amine2) assert mmff_energy.get_energy(tmp_amine2) == init_energy mmff2 = stk.MMFF(use_cache=True) mmff2.optimize(tmp_amine2) assert mmff_energy.get_energy(tmp_amine2) != init_energy
def test_optimizer_sequence(tmp_polymer): tmp_polymer.write(join(odir, 'optimize_sequence_before.mol')) etkdg = stk.RDKitEmbedder(rdkit.ETKDG()) mmff = stk.MMFF() sequence = stk.OptimizerSequence(etkdg, mmff) sequence.optimize(tmp_polymer) tmp_polymer.write(join(odir, 'optimize_sequence_after.mol'))
def test_mmff(tmp_polymer): # If the optimization was successful the energy should be lowered. energy_calculator = stk.MMFFEnergy() init_energy = energy_calculator.get_energy(tmp_polymer) tmp_polymer.write(join(odir, 'mmff_before.mol')) mmff = stk.MMFF() mmff.optimize(tmp_polymer) tmp_polymer.write(join(odir, 'mmff_after.mol')) assert energy_calculator.get_energy(tmp_polymer) < init_energy
def test_optimizer_sequence(tmp_polymer): # If the optimization was successful the energy should be lowered. energy_calculator = stk.MMFFEnergy() init_energy = energy_calculator.get_energy(tmp_polymer) tmp_polymer.write(join(odir, 'optimize_sequence_before.mol')) etkdg = stk.ETKDG() mmff = stk.MMFF() sequence = stk.OptimizerSequence(etkdg, mmff) sequence.optimize(tmp_polymer) tmp_polymer.write(join(odir, 'optimize_sequence_after.mol')) assert energy_calculator.get_energy(tmp_polymer) < init_energy
def test_cage_optimizer_sequence(tmp_opt_cc3, tmp_cc3): energy_calculator = stk.MMFFEnergy() init_opt_cc3 = energy_calculator.get_energy(tmp_opt_cc3) init_cc3 = energy_calculator.get_energy(tmp_cc3) mmff = stk.MMFF() sequence = stk.CageOptimizerSequence(mmff) sequence.optimize(tmp_opt_cc3) sequence.optimize(tmp_cc3) # opt_cc3 should have found all windows so energy should be lowered # due to optimization. assert energy_calculator.get_energy(tmp_opt_cc3) < init_opt_cc3 # cc3 should have not found all windows so energy should be the # same as if no optimization happened. assert energy_calculator.get_energy(tmp_cc3) == init_cc3
def test_raising_optimizer(tmp_polymer): mmff = stk.MMFF() always_raiser = stk.RaisingOptimizer( optimizer=mmff, fail_chance=1 ) with pytest.raises(stk.RaisingOptimizerError): always_raiser.optimize(tmp_polymer) never_raiser = stk.RaisingOptimizer( optimizer=mmff, fail_chance=0 ) tmp_polymer.write(join(odir, 'raising_optimizer_before.mol')) energy_calculator = stk.MMFFEnergy() energy_before = energy_calculator.get_energy(tmp_polymer) never_raiser.optimize(tmp_polymer) tmp_polymer.write(join(odir, 'raising_optimizer_after.mol')) assert energy_before > energy_calculator.get_energy(tmp_polymer)
def test_cage_optimizer_sequence(tmp_cc3, tmp_cage): mmff = stk.MMFF() etkdg = stk.RDKitEmbedder(rdkit.ETKDG()) sequence = stk.CageOptimizerSequence(etkdg, mmff) sequence.optimize(tmp_cage) sequence.optimize(tmp_cc3)
def test_mmff(tmp_polymer): tmp_polymer.write(join(odir, 'mmff_before.mol')) mmff = stk.MMFF() mmff.optimize(tmp_polymer) tmp_polymer.write(join(odir, 'mmff_after.mol'))