def test_convert_error_from_dg(): eps = 0.001 ############################################## # ORIGINAL = 'dg' ############################################## dg = utils.unit_registry.Quantity(1, utils.unit_registry("kJ / mole")) edg = utils.unit_registry.Quantity(0.1, utils.unit_registry("kJ / mole")) assert (pytest.approx(0.1, eps) == utils.convert_error( edg, dg, "dg", "dg", out_unit=utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(0.1, eps) == utils.convert_error( edg, dg, "dg", "dg", temperature=273, out_unit=utils.unit_registry("kJ / mole"), ).to(utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(0.0239, eps) == utils.convert_error( edg, dg, "dg", "dg", temperature=273, out_unit=utils.unit_registry("kJ / mole"), ).to(utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(0.026849, eps) == utils.convert_error( edg, dg, "dg", "ki").to(utils.unit_registry.molar).magnitude) assert (pytest.approx(0.026849, eps) == utils.convert_error( edg, dg, "dg", "ic50").to(utils.unit_registry.molar).magnitude) assert (pytest.approx(0.0174, eps) == utils.convert_error(edg, dg, "dg", "pic50").magnitude) with pytest.raises(NotImplementedError): assert "0.24 kcal/mol" == utils.convert_error(edg, dg, "dg", "fakeObs")
def test_affinity_data(): targets.set_data_dir(os.path.join(PLBenchmarks.__path__[0], "sample_data")) file = open( os.path.join(targets.get_target_data_path("mcl1_sample") + "ligands.yml") ) data = yaml.full_load_all(file) dfs = [] for d in data: lig = ligands.Ligand(d) lig.derive_observables( derived_type="dg", out_unit=utils.unit_registry("kcal / mole") ) lig.add_mol_to_frame() lig.get_image() dfs.append(lig.get_dataframe(["name", "ROMol", "DerivedMeasurement"])) df = pd.DataFrame(dfs) assert df.shape[0] == 15 for n in df.name: assert n in [ "lig_23", "lig_26", "lig_27", "lig_28", "lig_29", "lig_30", "lig_31", "lig_32", "lig_33", "lig_34", "lig_35", "lig_36", "lig_37", "lig_38", "lig_39", # "lig_40", # "lig_41", # "lig_42", # "lig_43", # "lig_44", # "lig_45", # "lig_46", # "lig_47", # "lig_48", # "lig_49", # "lig_50", # "lig_51", # "lig_52", # "lig_53", # "lig_54", # "lig_56", # "lig_57", # "lig_58", # "lig_60", # "lig_61", # "lig_62", # "lig_63", # "lig_64", # "lig_65", # "lig_66", # "lig_67", # "lig_68", ] # Check whether the values in the repo are the same and correctly converted by comparing to the values in the JACS paper jacs_data = { "lig_23": -8.83, "lig_26": -8.24, "lig_27": -6.12, "lig_28": -6.62, "lig_29": -6.94, "lig_30": -7.85, "lig_31": -7.92, "lig_32": -6.58, "lig_33": -6.88, "lig_34": -6.87, "lig_35": -8.81, "lig_36": -8.18, "lig_37": -8.95, "lig_38": -7.02, "lig_39": -7.03, # "lig_40": -7.25, # "lig_41": -7.13, # "lig_42": -8.9, # "lig_43": -7.03, # "lig_44": -8.67, # "lig_45": -8.95, # "lig_46": -7.6, # "lig_47": -5.78, # "lig_48": -6.66, # "lig_49": -8.36, # "lig_50": -9.33, # "lig_51": -8.45, # "lig_52": -9.23, # "lig_53": -9.96, # "lig_54": -9.78, # "lig_56": -9.26, # "lig_57": -9.04, # "lig_58": -9.41, # "lig_60": -8.92, # "lig_61": -8.08, # "lig_62": -7.96, # "lig_63": -9.06, # "lig_64": -9.5, # "lig_65": -8.41, # "lig_66": -8.43, # "lig_67": -7.58, # "lig_68": -7.69, } eps = 0.01 for key, item in jacs_data.items(): assert ( pytest.approx(item, eps) == df[df.name == key][("DerivedMeasurement", "dg")] .values[0] .to(utils.unit_registry("kcal / mole")) .magnitude )
def test_convert_value_from_ki(): eps = 0.001 ############################################## # ORIGINAL = 'ki' ############################################## ki = utils.unit_registry.Quantity(1, utils.unit_registry.molar) assert (pytest.approx(0.0, eps) == utils.convert_value( ki, "ki", "dg", temperature=300, out_unit=utils.unit_registry("kJ / mole")).to( utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(0.0, eps) == utils.convert_value( ki, "ki", "dg", temperature=273, out_unit=utils.unit_registry("kJ / mole")).to( utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(0.0, eps) == utils.convert_value( ki, "ki", "dg", out_unit=utils.unit_registry("kcal / mole")).to( utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(1.0, eps) == utils.convert_value( ki, "ki", "ki", out_unit=utils.unit_registry.molar).to( utils.unit_registry.molar).magnitude) assert (pytest.approx(1.0, eps) == utils.convert_value( ki, "ki", "ic50").to(utils.unit_registry.molar).magnitude) assert pytest.approx(0.0, eps) == utils.convert_value(ki, "ki", "pic50").magnitude with pytest.raises(NotImplementedError): assert "xxx" == utils.convert_value(ki, "ki", "fakeObs") ki = utils.unit_registry.Quantity(1, utils.unit_registry("nanomolar")) assert (pytest.approx(-51.69, eps) == utils.convert_value( ki, "ki", "dg", temperature=300, out_unit=utils.unit_registry("kJ / mole")).to( utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(-12.35, eps) == utils.convert_value(ki, "ki", "dg").to( utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(-12.35, eps) == utils.convert_value( ki, "ki", "dg", temperature=300).to(utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(-12.35, eps) == utils.convert_value( ki, "ki", "dg", temperature=300, out_unit=utils.unit_registry("kcal / mole")).to( utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(-47.04, eps) == utils.convert_value( ki, "ki", "dg", temperature=273, out_unit=utils.unit_registry("kJ / mole")).to( utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(1.00, eps) == utils.convert_value(ki, "ki", "ki").to( utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(1.00, eps) == utils.convert_value( ki, "ki", "ki", out_unit=utils.unit_registry("nanomolar")).to( utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(1.0, eps) == utils.convert_value(ki, "ki", "ic50").to( utils.unit_registry("nanomolar")).magnitude) assert pytest.approx(9, eps) == utils.convert_value(ki, "ki", "pic50").magnitude with pytest.raises(NotImplementedError): assert "xxx" == utils.convert_value(ki, "ki", "fakeObs")
def test_convert_error_from_pic50(): eps = 0.001 ############################################## # ORIGINAL = 'pic50' ############################################## pic50 = utils.unit_registry.Quantity(0, "") epic50 = utils.unit_registry.Quantity(0.5, "") assert (pytest.approx(2.87, eps) # 2.871712748 == utils.convert_error( epic50, pic50, "pic50", "dg", temperature=300.0, out_unit=utils.unit_registry("kJ / mole"), ).magnitude) assert (pytest.approx(2.61, eps) # 2.613258601 == utils.convert_error( epic50, pic50, "pic50", "dg", temperature=273.0, out_unit=utils.unit_registry("kJ / mole"), ).magnitude) assert (pytest.approx(0.69, eps) # 0.686356035 == utils.convert_error( epic50, pic50, "pic50", "dg", out_unit=utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(1.15, eps) # 1.151292546 == utils.convert_error( epic50, pic50, "pic50", "ki", out_unit=utils.unit_registry.molar).magnitude) assert (pytest.approx(1.15, eps) # 1.151292546 == utils.convert_error(epic50, pic50, "pic50", "ic50", out_unit=utils.unit_registry.molar).to( utils.unit_registry.molar).magnitude) assert (pytest.approx(0.5, eps) == utils.convert_error(epic50, pic50, "pic50", "pic50").magnitude) with pytest.raises(NotImplementedError): utils.convert_error(epic50, pic50, "pic50", "fakeObs") pic50 = utils.unit_registry.Quantity(9, "") epic50 = utils.unit_registry.Quantity(0.5, "") assert (pytest.approx(2.87, eps) # 2.871712748 == utils.convert_error( epic50, pic50, "pic50", "dg", temperature=300, out_unit=utils.unit_registry("kJ / mole"), ).magnitude) assert (pytest.approx(0.69, eps) # 0.686356035 == utils.convert_error(epic50, pic50, "pic50", "dg").to( utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(0.69, eps) # 0.686356035 == utils.convert_error( epic50, pic50, "pic50", "dg", temperature=300).to( utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(0.69, eps) # 0.686356035 == utils.convert_error( epic50, pic50, "pic50", "dg", temperature=300, out_unit=utils.unit_registry("kcal / mole"), ).magnitude) assert (pytest.approx(2.61, eps) # 2.613258601 == utils.convert_error( epic50, pic50, "pic50", "dg", temperature=273, out_unit=utils.unit_registry("kJ / mole"), ).magnitude) assert (pytest.approx(1.15, eps) # 1.151292546 == utils.convert_error(epic50, pic50, "pic50", "ki").to( utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(1.15, eps) # 1.151292546 == utils.convert_error(epic50, pic50, "pic50", "ic50").to( utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(1.15, eps) # 1.151292546 == utils.convert_error( epic50, pic50, "pic50", "ic50", out_unit=utils.unit_registry("nanomolar")).to( utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(0.5, eps) == utils.convert_error(epic50, pic50, "pic50", "pic50").magnitude) with pytest.raises(NotImplementedError): utils.convert_error(epic50, pic50, "pic50", "fakeObs")
def test_convert_error_from_ic50(): eps = 0.001 ############################################## # ORIGINAL = 'ic50' ############################################## ic50 = utils.unit_registry.Quantity(1, utils.unit_registry.molar) eic50 = utils.unit_registry.Quantity(0.1, utils.unit_registry.molar) assert (pytest.approx(0.25, eps) == utils.convert_error( eic50, ic50, "ic50", "dg", temperature=300, out_unit=utils.unit_registry("kJ / mole"), ).to(utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(0.23, eps) == utils.convert_error( eic50, ic50, "ic50", "dg", temperature=273, out_unit=utils.unit_registry("kJ / mole"), ).to(utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(0.06, eps) == utils.convert_error( eic50, ic50, "ic50", "dg", out_unit=utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(0.1, eps) == utils.convert_error( eic50, ic50, "ic50", "ki", out_unit=utils.unit_registry.molar).to( utils.unit_registry.molar).magnitude) assert (pytest.approx(0.1, eps) == utils.convert_error( eic50, ic50, "ic50", "ic50", out_unit=utils.unit_registry("nanomolar")).to( utils.unit_registry.molar).magnitude) assert (pytest.approx(0.04, eps) == utils.convert_error(eic50, ic50, "ic50", "pic50").magnitude) with pytest.raises(NotImplementedError): utils.convert_error(eic50, ic50, "ic50", "fakeObs") ic50 = utils.unit_registry.Quantity(1, utils.unit_registry("nanomolar")) eic50 = utils.unit_registry.Quantity(0.1, utils.unit_registry("nanomolar")) assert (pytest.approx(0.25, eps) == utils.convert_error( eic50, ic50, "ic50", "dg", temperature=300, out_unit=utils.unit_registry("kJ / mole"), ).magnitude) assert (pytest.approx(0.06, eps) == utils.convert_error( eic50, ic50, "ic50", "dg").to(utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(0.06, eps) == utils.convert_error( eic50, ic50, "ic50", "dg", temperature=300).to(utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(0.06, eps) == utils.convert_error( eic50, ic50, "ic50", "dg", temperature=300, out_unit=utils.unit_registry("kcal / mole"), ).magnitude) assert (pytest.approx(0.23, eps) == utils.convert_error( eic50, ic50, "ic50", "dg", temperature=273, out_unit=utils.unit_registry("kJ / mole"), ).magnitude) assert (pytest.approx(0.1, eps) == utils.convert_error( eic50, ic50, "ic50", "ki").to(utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(0.1, eps) == utils.convert_error( eic50, ic50, "ic50", "ki", out_unit=utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(0.1, eps) == utils.convert_error( eic50, ic50, "ic50", "ic50").to(utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(0.1, eps) == utils.convert_error( eic50, ic50, "ic50", "ic50", out_unit=utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(0.04, eps) == utils.convert_error(eic50, ic50, "ic50", "pic50").magnitude) with pytest.raises(NotImplementedError): utils.convert_error(eic50, ic50, "ic50", "fakeObs")
def test_convert_error_from_ki(): eps = 0.001 ############################################## # ORIGINAL = 'ki' ############################################## ki = utils.unit_registry.Quantity(1, utils.unit_registry.molar) eki = utils.unit_registry.Quantity(0.1, utils.unit_registry.molar) assert (pytest.approx(0.25, eps) == utils.convert_error( eki, ki, "ki", "dg", temperature=300, out_unit=utils.unit_registry("kJ / mole"), ).to(utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(0.23, eps) # 0.226984758 == utils.convert_error( eki, ki, "ki", "dg", temperature=273, out_unit=utils.unit_registry("kJ / mole"), ).to(utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(0.06, eps) # 0.059616175 == utils.convert_error( eki, ki, "ki", "dg", out_unit=utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(0.1, eps) == utils.convert_error( eki, ki, "ki", "ki", out_unit=utils.unit_registry.molar).to( utils.unit_registry.molar).magnitude) assert (pytest.approx(0.1, eps) == utils.convert_error( eki, ki, "ki", "ic50").to(utils.unit_registry.molar).magnitude) assert (pytest.approx(0.04, eps) # 0.043429448 == utils.convert_error(eki, ki, "ki", "pic50").magnitude) with pytest.raises(NotImplementedError): assert "xxx" == utils.convert_error(eki, ki, "ki", "fakeObs") ki = utils.unit_registry.Quantity(1, utils.unit_registry("nanomolar")) eki = utils.unit_registry.Quantity(0.1, utils.unit_registry("nanomolar")) assert (pytest.approx(0.25, eps) # 0.02494338 == utils.convert_error( eki, ki, "ki", "dg", temperature=300, out_unit=utils.unit_registry("kJ / mole"), ).magnitude) assert (pytest.approx(0.06, eps) == utils.convert_error( eki, ki, "ki", "dg").to(utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(0.06, eps) == utils.convert_error( eki, ki, "ki", "dg", temperature=300, out_unit=utils.unit_registry("kcal / mole"), ).magnitude) assert (pytest.approx(0.23, eps) == utils.convert_error( eki, ki, "ki", "dg", temperature=273, out_unit=utils.unit_registry("kJ / mole"), ).magnitude) assert (pytest.approx(0.1, eps) == utils.convert_error( eki, ki, "ki", "ki").to(utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(0.1, eps) == utils.convert_error( eki, ki, "ki", "ki", out_unit=utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(0.1, eps) == utils.convert_error( eki, ki, "ki", "ic50").to(utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(0.04, eps) == utils.convert_error(eki, ki, "ki", "pic50").magnitude) with pytest.raises(NotImplementedError): assert "xxx" == utils.convert_error(eki, ki, "ki", "fakeObs")
def test_convert_value_from_ic50(): eps = 0.001 ############################################## # ORIGINAL = 'pic50' ############################################## pic50 = utils.unit_registry.Quantity(0, "") assert (pytest.approx(0.0, eps) == utils.convert_value( pic50, "pic50", "dg", temperature=300.0, out_unit=utils.unit_registry("kJ / mole"), ).to(utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(0.0, eps) == utils.convert_value( pic50, "pic50", "dg", temperature=273.0, out_unit=utils.unit_registry("kJ / mole"), ).to(utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(0.0, eps) == utils.convert_value( pic50, "pic50", "dg", out_unit=utils.unit_registry("kcal / mole")).to( utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(1.0, eps) == utils.convert_value( pic50, "pic50", "ki", out_unit=utils.unit_registry.molar).to( utils.unit_registry.molar).magnitude) assert (pytest.approx(1.0, eps) == utils.convert_value( pic50, "pic50", "ic50", out_unit=utils.unit_registry.molar).to( utils.unit_registry.molar).magnitude) assert (pytest.approx(0.0, eps) == utils.convert_value(pic50, "pic50", "pic50").magnitude) with pytest.raises(NotImplementedError): utils.convert_value(pic50, "pic50", "fakeObs") pic50 = utils.unit_registry.Quantity(9, "") assert (pytest.approx(-51.69, eps) == utils.convert_value( pic50, "pic50", "dg", temperature=300, out_unit=utils.unit_registry("kJ / mole"), ).to(utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(-12.35, eps) == utils.convert_value( pic50, "pic50", "dg").to(utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(-12.35, eps) == utils.convert_value( pic50, "pic50", "dg", temperature=300).to(utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(-12.35, eps) == utils.convert_value( pic50, "pic50", "dg", temperature=300, out_unit=utils.unit_registry("kcal / mole"), ).to(utils.unit_registry("kcal / mole")).magnitude) assert (pytest.approx(-47.04, eps) == utils.convert_value( pic50, "pic50", "dg", temperature=273, out_unit=utils.unit_registry("kJ / mole"), ).to(utils.unit_registry("kJ / mole")).magnitude) assert (pytest.approx(1.00, eps) == utils.convert_value( pic50, "pic50", "ki").to(utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(1.00, eps) == utils.convert_value( pic50, "pic50", "ic50").to(utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(1.00, eps) == utils.convert_value( pic50, "pic50", "ic50", out_unit=utils.unit_registry("nanomolar")).to( utils.unit_registry("nanomolar")).magnitude) assert (pytest.approx(9, eps) == utils.convert_value(pic50, "pic50", "pic50").magnitude) with pytest.raises(NotImplementedError): utils.convert_value(pic50, "pic50", "fakeObs")