Has attribute#

Checking whether a molecular system has a specific attribute.

Not all molecular system forms include the same attributes, and not all molecular systems have values for every available attribute. For example, an openmm.Topology system supports a periodic box, but a particular molecular system might not define one. To check whether a molecular system has a specific attribute value, use molsysmt.basic.has_attribute().

Added in version 1.0.0.

Basic usage#

Let’s show how this function works with a demonstration dataset (pentalanine.inpcrd):

import molsysmt as msm
molsys = msm.systems['pentalanine']['pentalanine.inpcrd']
msm.has_attribute(molsys, attribute='box')
True

The function confirms that two conditions are met:

  • the “file:inpcrd” molecular system form has the attribute ‘box’

  • the molecular system has a value different from None for the attribute ‘box’.

Indeed, we can retrieve the corresponding value:

msm.get(molsys, box=True)
Magnitude
[[[4.29511093 0.0 0.0]  [-1.4317035278131303 4.049469460244502 0.0]  [-1.4317035278131303 -2.0247344850669022 3.506943565903758]]]
Unitsnanometer

A molecular system may support a given attribute, but the value may still be None. In this case the function molsysmt.basic.has_attribute() returns False. Let’s see this case with the following example:

molsys = msm.convert(msm.systems['pentalanine']['pentalanine.prmtop'], to_form='openmm.Topology')
msm.set(molsys, box=None)
msm.has_attribute(molsys, attribute='box')
False

We can check whether a specific form (regardless of system instance) supports an attribute using molsysmt.form.has_attribute().

msm.form.has_attribute('file:prmtop', attribute='box')
True

Finally, let’s see how molsysmt.basic.has_attribute() behaves when the requested attribute is not supported by the molecular system’s form.

molecular_system = msm.systems['pentalanine']['pentalanine.prmtop']
msm.has_attribute(molsys, attribute='coordinates')
False