def test_lennard_jones_handler(): patterns = [ ['[#1:1]', 99., 999.], ['[#1:1]-[#6X4]', 99., 999.], ['[#1:1]-[#6X4]-[#7,#8,#9,#16,#17,#35]', 99., 999.], ['[#1:1]-[#6X4](-[#7,#8,#9,#16,#17,#35])-[#7,#8,#9,#16,#17,#35]', 99., 999.], ['[#1:1]-[#6X4](-[#7,#8,#9,#16,#17,#35])(-[#7,#8,#9,#16,#17,#35])-[#7,#8,#9,#16,#17,#35]', 99., 999.], ['[#1:1]-[#6X4]~[*+1,*+2]', 99., 999.], ['[#1:1]-[#6X3]', 99., 999.], ['[#1:1]-[#6X3]~[#7,#8,#9,#16,#17,#35]', 99., 999.], ['[#1:1]-[#6X3](~[#7,#8,#9,#16,#17,#35])~[#7,#8,#9,#16,#17,#35]', 99., 999.], ['[#1:1]-[#6X2]', 99., 999.], ['[#1:1]-[#7]', 99., 999.], ['[#1:1]-[#8]', 99., 999.], ['[#1:1]-[#16]', 99., 999.], ['[#6:1]', 0.7, 0.8], ['[#6X2:1]', 99., 999.], ['[#6X4:1]', 0.1, 0.2], ['[#8:1]', 99., 999.], ['[#8X2H0+0:1]', 0.5, 0.6], ['[#8X2H1+0:1]', 99., 999.], ['[#7:1]', 0.3, 0.4], ['[#16:1]', 99., 999.], ['[#15:1]', 99., 999.], ['[#9:1]', 1.0, 1.1], ['[#17:1]', 99., 999.], ['[#35:1]', 99., 999.], ['[#53:1]', 99., 999.], ['[#3+1:1]', 99., 999.], ['[#11+1:1]', 99., 999.], ['[#19+1:1]', 99., 999.], ['[#37+1:1]', 99., 999.], ['[#55+1:1]', 99., 999.], ['[#9X0-1:1]', 99., 999.], ['[#17X0-1:1]', 99., 999.], ['[#35X0-1:1]', 99., 999.], ['[#53X0-1:1]', 99., 999.], ] smirks = [x[0] for x in patterns] params = np.array([[x[1], x[2]] for x in patterns]) props = None ljh = nonbonded.LennardJonesHandler(smirks, params, props) obj = ljh.serialize() all_handlers = deserialize(bin_to_str(obj)) ljh = all_handlers[0] np.testing.assert_equal(ljh.smirks, ljh.smirks) np.testing.assert_equal(ljh.params, ljh.params) assert ljh.props == ljh.props
def test_lennard_jones_handler(): patterns = [ ['[#1:1]', 99., 999.], ['[#1:1]-[#6X4]', 99., 999.], ['[#1:1]-[#6X4]-[#7,#8,#9,#16,#17,#35]', 99., 999.], ['[#1:1]-[#6X4](-[#7,#8,#9,#16,#17,#35])-[#7,#8,#9,#16,#17,#35]', 99., 999.], ['[#1:1]-[#6X4](-[#7,#8,#9,#16,#17,#35])(-[#7,#8,#9,#16,#17,#35])-[#7,#8,#9,#16,#17,#35]', 99., 999.], ['[#1:1]-[#6X4]~[*+1,*+2]', 99., 999.], ['[#1:1]-[#6X3]', 99., 999.], ['[#1:1]-[#6X3]~[#7,#8,#9,#16,#17,#35]', 99., 999.], ['[#1:1]-[#6X3](~[#7,#8,#9,#16,#17,#35])~[#7,#8,#9,#16,#17,#35]', 99., 999.], ['[#1:1]-[#6X2]', 99., 999.], ['[#1:1]-[#7]', 99., 999.], ['[#1:1]-[#8]', 99., 999.], ['[#1:1]-[#16]', 99., 999.], ['[#6:1]', 0.7, 0.8], ['[#6X2:1]', 99., 999.], ['[#6X4:1]', 0.1, 0.2], ['[#8:1]', 99., 999.], ['[#8X2H0+0:1]', 0.5, 0.6], ['[#8X2H1+0:1]', 99., 999.], ['[#7:1]', 0.3, 0.4], ['[#16:1]', 99., 999.], ['[#15:1]', 99., 999.], ['[#9:1]', 1.0, 1.1], ['[#17:1]', 99., 999.], ['[#35:1]', 99., 999.], ['[#53:1]', 99., 999.], ['[#3+1:1]', 99., 999.], ['[#11+1:1]', 99., 999.], ['[#19+1:1]', 99., 999.], ['[#37+1:1]', 99., 999.], ['[#55+1:1]', 99., 999.], ['[#9X0-1:1]', 99., 999.], ['[#17X0-1:1]', 99., 999.], ['[#35X0-1:1]', 99., 999.], ['[#53X0-1:1]', 99., 999.], ] smirks = [x[0] for x in patterns] params = np.array([[x[1], x[2]] for x in patterns]) props = None ljh = nonbonded.LennardJonesHandler(smirks, params, props) mol = Chem.MolFromSmiles("C1CNCOC1F") lj_params = ljh.parameterize(mol) ligand_params = np.array([ [0.1/2, 0.2], # C [0.1/2, 0.2], # C [0.3/2, 0.4], # N [0.1/2, 0.2], # C [0.5/2, 0.6], # O [0.1/2, 0.2], # C [1.0/2, 1.1] # F ]) np.testing.assert_almost_equal(lj_params, ligand_params) lj_params_adjoints = np.random.randn(*lj_params.shape) new_lj_params, lj_vjp_fn = jax.vjp(functools.partial(ljh.partial_parameterize, mol=mol), params) np.testing.assert_array_equal(new_lj_params, lj_params) # test that we can use the adjoints adjoints = lj_vjp_fn(lj_params_adjoints)[0] # if a parameter is > 99 then its adjoint should be zero (converse isn't necessarily true since) mask = np.argwhere(params > 90) assert np.all(adjoints[mask] == 0.0) == True