Exemplo n.º 1
0
 def test_to_list(self):
     """Test basic ParameterList.to_list() function, ensuring units are preserved"""
     from simtk import unit
     p1 = BondHandler.BondType(smirks='[*:1]-[*:2]',
                               length=1.01 * unit.angstrom,
                               k=5 * unit.kilocalorie_per_mole /
                               unit.angstrom**2)
     p2 = BondHandler.BondType(smirks='[*:1]=[*:2]',
                               length=1.02 * unit.angstrom,
                               k=6 * unit.kilocalorie_per_mole /
                               unit.angstrom**2)
     p3 = BondHandler.BondType(smirks='[*:1]#[*:3]',
                               length=1.03 * unit.angstrom,
                               k=7 * unit.kilocalorie_per_mole /
                               unit.angstrom**2)
     parameter_list = ParameterList([p1, p2, p3])
     ser_param_list = parameter_list.to_list()
     assert len(ser_param_list) == 3
     assert ser_param_list[0]['length'] == 1.01 * unit.angstrom
Exemplo n.º 2
0
    def test_read_write_optional_parameter_attribute(self):
        """
        Test ParameterTypes' ability to store and write out optional attributes passed to __init__()
        """
        from simtk import unit

        p1 = BondHandler.BondType(smirks='[*:1]-[*:2]',
                                  length=1.02 * unit.angstrom,
                                  k=5 * unit.kilocalorie_per_mole /
                                  unit.angstrom**2,
                                  id='b1')
        param_dict = p1.to_dict()
        assert ('id', 'b1') in param_dict.items()
Exemplo n.º 3
0
 def test_round_trip(self):
     """Test basic ParameterList.to_list() function and constructor"""
     from simtk import unit
     p1 = BondHandler.BondType(smirks='[*:1]-[*:2]',
                               length=1.01 * unit.angstrom,
                               k=5 * unit.kilocalorie_per_mole /
                               unit.angstrom**2)
     p2 = BondHandler.BondType(smirks='[*:1]=[*:2]',
                               length=1.02 * unit.angstrom,
                               k=6 * unit.kilocalorie_per_mole /
                               unit.angstrom**2)
     p3 = BondHandler.BondType(smirks='[*:1]#[*:3]',
                               length=1.03 * unit.angstrom,
                               k=7 * unit.kilocalorie_per_mole /
                               unit.angstrom**2)
     parameter_list = ParameterList([p1, p2, p3])
     param_dict_list = parameter_list.to_list()
     parameter_list_2 = ParameterList()
     for param_dict in param_dict_list:
         new_parameter = BondHandler.BondType(**param_dict)
         parameter_list_2.append(new_parameter)
     assert parameter_list.to_list() == parameter_list_2.to_list()
Exemplo n.º 4
0
    def test_error_cosmetic_parameter_attribute(self):
        """
        Test that ParameterTypes raise an error on receiving unexpected attributes passed to __init__()
        """
        from simtk import unit

        with pytest.raises(SMIRNOFFSpecError, match="Unexpected kwarg (pilot: alice)*") as context:
            p1 = BondHandler.BondType(smirks='[*:1]-[*:2]',
                                      length=1.02*unit.angstrom,
                                      k=5 * unit.kilocalorie_per_mole / unit.angstrom ** 2,
                                      pilot='alice',
                                      allow_cosmetic_attributes=False
                                      )
Exemplo n.º 5
0
    def test_read_but_dont_write_cosmetic_parameter_attribute(self):
        """
        Test ParameterTypes' ability to ignore cosmetic attributes passed to __init__() if instructed
        """
        from simtk import unit

        p1 = BondHandler.BondType(smirks='[*:1]-[*:2]',
                                  length=1.02 * unit.angstrom,
                                  k=5 * unit.kilocalorie_per_mole /
                                  unit.angstrom**2,
                                  pilot='alice',
                                  allow_cosmetic_attributes=True)
        param_dict = p1.to_dict(discard_cosmetic_attributes=True)
        assert ('pilot', 'alice') not in param_dict.items()
Exemplo n.º 6
0
 def test_bondtype_to_dict_custom_output_units(self):
     """
     Test BondType to_dict with custom output units.
     """
     from simtk import unit
     p1 = BondHandler.BondType(smirks='[*:1]-[*:2]',
                               length=1.02 * unit.angstrom,
                               k=5 * unit.kilocalorie_per_mole /
                               unit.angstrom**2)
     param_dict = p1.to_dict()
     param_dict_unitless, attached_units = detach_units(
         param_dict, output_units={'length_unit': unit.nanometer})
     assert attached_units['length_unit'] == unit.nanometer
     assert abs(param_dict_unitless['length'] - 0.102) < 1e-10
Exemplo n.º 7
0
 def test_bondtype_to_dict_invalid_output_units(self):
     """
     Test ParameterType to_dict with invalid output units.
     """
     from simtk import unit
     p1 = BondHandler.BondType(smirks='[*:1]-[*:2]',
                               length=1.02*unit.angstrom,
                               k=5 * unit.kilocalorie_per_mole / unit.angstrom ** 2
                               )
     param_dict = p1.to_dict()
     with pytest.raises(ValueError,
                        match='Requested output unit calorie is not compatible with quantity unit angstrom .'
                        ) as context:
         param_dict_unitless, attached_units = detach_units(param_dict, output_units = {'length_unit':
                                                                                            unit.calorie})
Exemplo n.º 8
0
    def test_bondtype_to_dict(self):
        """
        Test BondType to_dict.
        """
        from simtk import unit

        p1 = BondHandler.BondType(smirks='[*:1]-[*:2]',
                                  length=1.02 * unit.angstrom,
                                  k=5 * unit.kilocalorie_per_mole / unit.angstrom ** 2
                                  )
        param_dict = p1.to_dict()
        param_dict_unitless, attached_units = detach_units(param_dict)
        assert param_dict_unitless == {'smirks': '[*:1]-[*:2]',
                                       'length': 1.02,
                                       'k': 5,}
        assert attached_units == {'length_unit': unit.angstrom,
                                  'k_unit': (unit.angstrom ** -2) * (unit.mole ** -1) * (unit.kilocalorie ** 1)
                                  }
Exemplo n.º 9
0
    def test_add_delete_cosmetic_attrib(self):
        """
        Test adding and deleting cosmetic attributes for already-initialized ParameterType objects
        """
        from simtk import unit

        p1 = BondHandler.BondType(smirks='[*:1]-[*:2]',
                                  length=1.02*unit.angstrom,
                                  k=5 * unit.kilocalorie_per_mole / unit.angstrom ** 2,
                                  )
        # Ensure the cosmetic attribute is present by default during output
        p1.add_cosmetic_attribute('pilot', 'alice')
        param_dict = p1.to_dict()
        assert ('pilot', 'alice') in param_dict.items()

        # Ensure the cosmetic attribute isn't present if we request that it be discarded
        param_dict = p1.to_dict(discard_cosmetic_attributes=True)
        assert ('pilot', 'alice') not in param_dict.items()

        # Manually delete the cosmetic attribute and ensure it doesn't get written out
        p1.delete_cosmetic_attribute('pilot')
        param_dict = p1.to_dict()
        assert ('pilot', 'alice') not in param_dict.items()