示例#1
0
 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')
示例#2
0
 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')
示例#3
0
 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}
示例#4
0
    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})
示例#5
0
 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
示例#6
0
 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
示例#7
0
 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}
示例#8
0
    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})
示例#9
0
 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}
示例#10
0
 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",
         )
示例#11
0
 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}
示例#12
0
 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