def test_basic_load(file_3nob): assert molecule.num() == 0 assert molecule.listall() == [] m = molecule.load("mae", file_3nob) assert molecule.num() == 1 assert molecule.listall() == [m] assert molecule.exists(m) assert not molecule.exists(m + 1) assert molecule.name(m) == "3nob.mae" with pytest.raises(ValueError): molecule.name(m + 1) molecule.rename(m, "newname") assert molecule.name(m) == "newname" with pytest.raises(ValueError): molecule.rename(name="wrong id", molid=m + 1) assert molecule.numatoms(molid=m) == 2481 with pytest.raises(ValueError): molecule.numatoms(m + 1) molecule.delete(m) with pytest.raises(ValueError): molecule.delete(m)
def test_basic_load(file_3nob): assert molecule.num() == 0 assert molecule.listall() == [] m = molecule.load("mae", file_3nob) assert molecule.num() == 1 assert molecule.listall() == [m] assert molecule.exists(m) assert not molecule.exists(m+1) assert molecule.name(m) == "3nob.mae" with pytest.raises(ValueError): molecule.name(m+1) molecule.rename(m, "newname") assert molecule.name(m) == "newname" with pytest.raises(ValueError): molecule.rename(name="wrong id", molid=m+1) assert molecule.numatoms(molid=m) == 2481 with pytest.raises(ValueError): molecule.numatoms(m+1) molecule.delete(m) with pytest.raises(ValueError): molecule.delete(m)
def __init__(self, name=None, id=None, atoms=0): """ Creating a new Molecule instance with no arguments will create a new empty molecule in VMD. Passing a valid molecule id will make the Molecule instance mirror the state of the corresponding molecule in VMD. If id is None, and a name is given, the new molecule will have that name. """ if id is None: if name is None: name = "molecule" self.id = molecule.new(name, atoms) else: self.id = id self.atoms = molecule.numatoms(self.id) if not molecule.exists(self.id): raise ValueError("Molecule with id %d does not exist." % self.id)
def num_waters_remaining(molid, water_sel='water and element O'): """ Returns the number of waters remaining in the system, indicated by the value of the beta flag. Args: molid (int): VMD molecule id to consider sel (str): VMD atom selection that counts as water, defaults to 'water and element O' Returns: (int) number of water molecules remaining in the system Raises: ValueError if empty water selection ValueError if non-existent molecule given """ if not len(water_sel): raise ValueError("Empty water selection string") if not molecule.exists(molid): raise ValueError("Invalid molecule %d" % molid) return len(atomsel_remaining(molid, water_sel))
def num_waters_remaining(molid, water_sel='water and element O'): """ Returns the number of waters remaining in the system, indicated by the value of the beta flag. Args: molid (int): VMD molecule id to consider sel (str): VMD atom selection that counts as water, defaults to 'water and element O' Returns: (int) number of water molecules remaining in the system Raises: ValueError if empty water selection ValueError if non-existent molecule given """ if not water_sel: raise ValueError("Empty water selection string") if not molecule.exists(molid): raise ValueError("Invalid molecule %d" % molid) return len(atomsel_remaining(molid, water_sel))
def num_lipids_remaining(molid, lipid_sel): """ Returns the number of lipids remaining in the system, indicated by the value of the beta flag. Uses the fragment notation to count the number of lipids. Args: molid (int): VMD molecule ID to consider lipid_sel (str): VMD atom selection that counts as lipid Returns: (int) number of lipid molecules remaining in the system Raises: ValueError if empty lipid selection ValueError if non-existent molecule given """ if not len(lipid_sel): raise ValueError("Empty lipid selection string") if not molecule.exists(molid): raise ValueError("Invalid molecule %d" % molid) return np.unique(atomsel_remaining(molid, lipid_sel).get('fragment')).size
def num_lipids_remaining(molid, lipid_sel): """ Returns the number of lipids remaining in the system, indicated by the value of the beta flag. Uses the fragment notation to count the number of lipids. Args: molid (int): VMD molecule ID to consider lipid_sel (str): VMD atom selection that counts as lipid Returns: (int) number of lipid molecules remaining in the system Raises: ValueError if empty lipid selection ValueError if non-existent molecule given """ if not lipid_sel: raise ValueError("Empty lipid selection string") if not molecule.exists(molid): raise ValueError("Invalid molecule %d" % molid) return np.unique(atomsel_remaining(molid, lipid_sel).fragment).size