def test_class_method(self): template = PotentialTemplateLibrary()['HarmonicBondPotential'] params = {'k': 1.0 * u.dimensionless, 'r_eq': 1.0 * u.dimensionless} harmonic_potential_from_template = ParametricPotential.from_template(template, params) harmonic_potential = ParametricPotential(name='HarmonicBondPotential', expression='0.5 * k * (r-r_eq)**2', independent_variables={'r'}, parameters=params) assert harmonic_potential.name == harmonic_potential_from_template.name assert harmonic_potential.expression == harmonic_potential_from_template.expression assert harmonic_potential.independent_variables == harmonic_potential_from_template.independent_variables
def test_class_method(self): template = PotentialTemplateLibrary()["HarmonicBondPotential"] params = {"k": 1.0 * u.dimensionless, "r_eq": 1.0 * u.dimensionless} harmonic_potential_from_template = ParametricPotential.from_template( template, params) harmonic_potential = ParametricPotential( name="HarmonicBondPotential", expression="0.5 * k * (r-r_eq)**2", independent_variables={"r"}, parameters=params, ) assert harmonic_potential.name == harmonic_potential_from_template.name assert (harmonic_potential.expression == harmonic_potential_from_template.expression) assert (harmonic_potential.independent_variables == harmonic_potential_from_template.independent_variables)
def test_ethane_periodic(self, typed_ethane): from gmso.lib.potential_templates import PotentialTemplateLibrary from gmso.core.parametric_potential import ParametricPotential per_torsion = PotentialTemplateLibrary()["PeriodicTorsionPotential"] params = {"k" : 10 * u.Unit("kJ / mol"), "phi_eq" : 15 * u.Unit("degree"), "n" : 3 * u.Unit("dimensionless")} periodic_dihedral_type = ParametricPotential.from_template( potential_template=per_torsion, parameters=params ) for dihedral in typed_ethane.dihedrals: dihedral.connection_type = periodic_dihedral_type typed_ethane.update_connection_types() write_top(typed_ethane, 'system.top') struct = pmd.load_file('system.top') assert len(struct.dihedrals) == 9
def test_class_method_with_error(self): template = object() with pytest.raises(GMSOError): ParametricPotential.from_template(template, parameters=None)