def test_set_nb_func_bad(self): # Try changing the nonbonded function, keep the parameters, # but the nb function uses different symbols first_type = AtomType(expression='r*sigma*epsilon', parameters={'sigma': 1*u.m, 'epsilon': 100*u.m}, independent_variables='r') with pytest.raises(ValueError): first_type.set_expression(expression='a + b')
def test_set_nb_func_params_both_incorrect(self): # Try incorrectly changing both the nb function and the parameters first_type = AtomType(expression='r*sigma*epsilon', parameters={'sigma': 1*u.m, 'epsilon': 10*u.J}, independent_variables='r') with pytest.raises(ValueError): first_type.set_expression(expression='a*x+b', parameters={'c': 100*u.year, 'd': 42*u.newton}, independent_variables='x')
def test_set_nb_func(self, charge): # Try changing the nonbonded function, but keep the parameters first_type = AtomType(name='mytype', charge=charge, parameters={'sigma': 1*u.m, 'epsilon': 10*u.m}, independent_variables='r') first_type.set_expression(expression='r * (sigma + epsilon)') correct_expr = sympy.sympify('r * (sigma + epsilon)') assert first_type.expression == correct_expr assert first_type.parameters == {'sigma': 1*u.m, 'epsilon': 10*u.m}
def test_set_nb_func_params_bad(self): # Try changing the parameters, keep the function, # but the new parameters use different symbols first_type = AtomType(expression='r*sigma*epsilon', parameters={'sigma': 1*u.m, 'epsilon': 10*u.J}, independent_variables={'r'}) with pytest.raises(ValueError): first_type.set_expression(parameters={'a': 1*u.g, 'b': 10*u.m})
def test_set_nb_func_params_both_correct(self): # Try correctly changing both the nb function and parameters first_type = AtomType(expression='r*sigma*epsilon', parameters={'sigma': 1*u.m, 'epsilon': 10*u.J}, independent_variables='r') first_type.set_expression(expression='a+b*x', parameters={'a': 100*u.m, 'b': 42*u.J}, independent_variables='x') correct_expr = sympy.sympify('a+b*x') correct_params = {'a': 100*u.m, 'b': 42*u.J} assert first_type.expression == correct_expr assert first_type.parameters == correct_params
def test_set_nb_func_params_partial(self): # Try changing the parameters, keep the function, # but change only one symbol first_type = AtomType(expression='r*sigma*epsilon', parameters={'sigma': 1*u.m, 'epsilon': 10*u.J}, independent_variables={'r'}) first_type.set_expression(parameters={'sigma': 42*u.m}) correct_expr = sympy.sympify('r*sigma*epsilon') assert first_type.parameters == {'sigma': 42*u.m, 'epsilon': 10*u.J} assert first_type.expression == correct_expr
def test_set_nb_func_params(self, charge): # Try changing the nb parameters, but keeping the function first_type = AtomType(name='mytype', charge=charge, expression='r * sigma * epsilon', parameters={'sigma': 1*u.m, 'epsilon': 10*u.m}, independent_variables='r') first_type.set_expression(parameters={'sigma': 42*u.m, 'epsilon': 24*u.m}) correct_expr = sympy.sympify('r * sigma * epsilon') assert first_type.expression == correct_expr assert first_type.parameters == {'sigma': 42, 'epsilon': 24}
def test_set_nb_func_params_bad(self): # Try changing the parameters, keep the function, # but the new parameters use different symbols first_type = AtomType( expression="r*sigma*epsilon", parameters={"sigma": 1 * u.m, "epsilon": 10 * u.J}, independent_variables={"r"}, ) with pytest.raises(ValueError): first_type.set_expression(parameters={"a": 1 * u.g, "b": 10 * u.m})
def test_set_nb_func(self, charge): # Try changing the nonbonded function, but keep the parameters first_type = AtomType( name="mytype", charge=charge, parameters={"sigma": 1 * u.m, "epsilon": 10 * u.m}, independent_variables="r", ) first_type.set_expression(expression="r * (sigma + epsilon)") correct_expr = sympy.sympify("r * (sigma + epsilon)") assert first_type.expression == correct_expr assert first_type.parameters == {"sigma": 1 * u.m, "epsilon": 10 * u.m}
def test_set_nb_func_params_both_incorrect(self): # Try incorrectly changing both the nb function and the parameters first_type = AtomType( expression="r*sigma*epsilon", parameters={"sigma": 1 * u.m, "epsilon": 10 * u.J}, independent_variables="r", ) with pytest.raises(ValueError): first_type.set_expression( expression="a*x+b", parameters={"c": 100 * u.year, "d": 42 * u.newton}, independent_variables="x", )
def test_set_nb_func_params(self, charge): # Try changing the nb parameters, but keeping the function first_type = AtomType( name="mytype", charge=charge, expression="r * sigma * epsilon", parameters={"sigma": 1 * u.m, "epsilon": 10 * u.m}, independent_variables="r", ) first_type.set_expression( parameters={"sigma": 42 * u.m, "epsilon": 24 * u.m} ) correct_expr = sympy.sympify("r * sigma * epsilon") assert first_type.expression == correct_expr assert first_type.parameters == {"sigma": 42, "epsilon": 24}
def test_set_nb_func_params_both_correct(self): # Try correctly changing both the nb function and parameters first_type = AtomType( expression="r*sigma*epsilon", parameters={"sigma": 1 * u.m, "epsilon": 10 * u.J}, independent_variables="r", ) first_type.set_expression( expression="a+b*x", parameters={"a": 100 * u.m, "b": 42 * u.J}, independent_variables="x", ) correct_expr = sympy.sympify("a+b*x") correct_params = {"a": 100 * u.m, "b": 42 * u.J} assert first_type.expression == correct_expr assert first_type.parameters == correct_params