def test_set_expression_bad(self): potential = Potential(name='mypotential', expression='a*x+b', parameters={ 'a': 1.0 * u.g, 'b': 1.0 * u.m }, independent_variables={'x'}) with pytest.raises(ValueError): potential.set_expression(expression='a*x**2+b*x+c')
def test_set_params_partial(self): potential = Potential(name='mypotential', expression='a*x+b', parameters={ 'a': 1.0 * u.g, 'b': 1.0 * u.m }, independent_variables={'x'}) potential.set_expression(parameters={'a': 4.0 * u.g}) assert potential.expression == sympy.sympify('a*x+b') assert potential.parameters == {'a': 4 * u.g, 'b': 1 * u.m}
def test_set_expression(self): # Try changing the expression but keep the parameters potential = Potential(name='mypotential', expression='a*x+b', parameters={ 'a': 1.0 * u.g, 'b': 1.0 * u.m }, independent_variables={'x'}) potential.set_expression(expression='a*x**2+b') assert potential.expression == sympy.sympify('a*x**2+b') assert potential.parameters == {'a': 1 * u.g, 'b': 1 * u.m}
def test_set_expression_and_params_mismatch(self): potential = Potential(name='mypotential', expression='a*x+b', parameters={ 'a': 1.0 * u.g, 'b': 1.0 * u.m }, independent_variables={'x'}) with pytest.raises(ValueError): potential.set_expression( expression='c*x+d', parameters={ 'u': 1.0 * u.g, 'v': 1.0 * u.m }, )
def test_setters(self): new_potential = Potential() new_potential.name = "SettingName" new_potential.set_expression( independent_variables=sympy.symbols({'r'}), expression='r*sigma*epsilon', parameters={ 'sigma': 1 * u.nm, 'epsilon': 10 * u.Unit('kcal / mol') } ) assert new_potential.name == "SettingName" assert new_potential.independent_variables == {sympy.symbols('r')} assert new_potential.parameters == { 'sigma': 1 * u.nm, 'epsilon': 10 * u.Unit('kcal / mol') } assert new_potential.expression == sympy.sympify('r * sigma * epsilon')
def test_set_expression_and_params(self): potential = Potential( name='mypotential', expression='a*x+b', parameters={ 'a': 1.0*u.g, 'b': 1.0*u.m}, independent_variables={'x'} ) potential.set_expression( expression='u*r+v', parameters={ 'u': 1.0*u.g, 'v': 1.0*u.m}, independent_variables={'r'} ) assert potential.expression == sympy.sympify('u*r+v') assert potential.parameters == { 'u': 1*u.g, 'v': 1*u.m}