def test_atom_gro_line(self, atom_gro1: AtomGro, atom_gro3: AtomGro): """ Tests gro_line method. """ info = [ 1, 'BMIM', 'N1', 1, 4.668, 3.571, 8.232, -0.2489, 0.2514, 0.1046 ] assert atom_gro1.gro_line() == info line = ' 1BMIM N1 1 4.668 3.571 8.232 -0.2489 0.2514 0.1046' line_compare = atom_gro1.gro_line(parsed=False) assert isinstance(line_compare, str) assert line_compare.strip() == line.strip() assert len(atom_gro3.gro_line()) == 7
def test_initialization(self): """ Initialization test. """ atom = AtomGro( (1, 'BMIM', 'N1', 1, 4.668, 3.571, 8.232, -0.2489, 0.2514, 0.1046)) assert atom.resid == 1 assert atom.resname == 'BMIM' assert atom.name == 'N1' assert atom.atomid == 1 assert np.isclose(atom.position, (4.668, 3.571, 8.232)).all() assert np.isclose(atom.velocity, (-0.2489, 0.2514, 0.1046)).all() atom = AtomGro((1, 'BMIM', 'N1', 1, 4.668, 3.571, 8.232)) assert atom.velocity is None
def residue_bmim() -> Residue: """ BMIM Residue instance. """ fname = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BMIM_AA.gro') with GroFile(fname) as fgro: atoms = [AtomGro(line) for line in fgro] return Residue(atoms)
def residue_protein() -> List[Residue]: """ List of Residue instances for a molecule with multiple residues. """ fname = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/Protein_CG.gro') residues: List[Residue] = [] with GroFile(fname) as fgro: atom = AtomGro(next(fgro)) residname = atom.residname atoms = [atom] for line in fgro: atom = AtomGro(line) if residname != atom.residname: residues.append(Residue(atoms)) residname = atom.residname atoms = [atom] else: atoms.append(atom) residues.append(Residue(atoms)) return residues
def vte_aa() -> Molecule: """ Molecule instance of vitamin E all-atom. """ fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/VTE_AA.gro') with GroFile(fgro) as _file: atoms = [AtomGro(line) for line in _file] mgro = Residue(atoms) fitp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/VTE_AA.itp') mitp = MoleculeTop(fitp) return Molecule(mitp, [mgro])
def molecule_cg() -> Molecule: """ Molecule instance of curcumine coarse-grained. """ fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/CUR_map.gro') with GroFile(fgro) as _file: atoms = [AtomGro(line) for line in _file] mgro = Residue(atoms) fitp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/CUR_CG.itp') mitp = MoleculeTop(fitp) return Molecule(mitp, [mgro])
def molecule_aa() -> Molecule: """ Molecule instance of curcumine in all-atom resolution. """ fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/CUR_AA.gro') with GroFile(fgro) as _file: atoms = [AtomGro(line) for line in _file] mgro = Residue(atoms) fitp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/CUR_AA.itp') mitp = MoleculeTop(fitp) return Molecule(mitp, [mgro])
def vte_map_cg() -> Molecule: """ Molecule instance of vitamin E coarse-grained coming from the map process. """ fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/VTE_map.gro') with GroFile(fgro) as _file: atoms = [AtomGro(line) for line in _file] mgro = Residue(atoms) fitp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/vitamin_E_CG.itp') mitp = MoleculeTop(fitp) return Molecule(mitp, [mgro])
def test_write_gro(self, molecule_protein: Molecule, tmp_path: Path): """ Test for writing gro files. """ subdir = tmp_path / "molecule_test" subdir.mkdir() fgrotmp = str(subdir / "test_write_gro.gro") molecule_protein.write_gro(fgrotmp) with GroFile(fgrotmp) as fgro: assert fgro.natoms == 34 for line, atom in zip(fgro, molecule_protein): atom_gro = AtomGro(line) assert atom.atom_gro == atom_gro
def test_methods(self, atom_gro1: AtomGro, atom_gro2: AtomGro, atom_gro3: AtomGro): """ Tests simple methods and magic-methods. """ assert atom_gro1 == atom_gro1 assert atom_gro1 != atom_gro2 assert atom_gro1 != 1 copy_1 = atom_gro1.copy() assert copy_1 == atom_gro1 assert copy_1 is not atom_gro1 assert atom_gro1.residname == '1BMIM' assert atom_gro2.residname == '1BMIM' assert atom_gro3.residname == '1BF4' assert atom_gro1.element == 'N' assert atom_gro2.element == 'H' assert atom_gro3.element == 'H' atom_gro1.name = '345' with pytest.raises(IOError): _ = atom_gro1.element
def test_write_gro(self, residue: Residue, tmp_path: Path): """ Test for writing gro files. """ subdir = tmp_path / "residue_test" subdir.mkdir() fgrotmp = str(subdir / "test_write_gro.gro") residue.write_gro(fgrotmp) atoms = [] with GroFile(fgrotmp) as fgro: assert fgro.natoms == 2 for line in fgro: atoms.append(AtomGro(line)) new_residue = Residue(atoms) assert new_residue == residue
def generate_atom_gro(resid: int = 1, resname: str = 'BMIM', name: str = 'N1', atomid: int = 1) -> AtomGro: info = (resid, resname, name, atomid, 4.668, 3.571, 8.232, -0.2489, 0.2514, 0.1046) return AtomGro(info)
def atom_gro3() -> AtomGro: info = (1, 'BF4', 'H2', 2, 5.668, 3.571, 8.232) return AtomGro(info)
def atom_gro2() -> AtomGro: info = (1, 'BMIM', 'H2', 2, 5.668, 3.571, 8.232, -0.2489, 0.2514, 0.1046) return AtomGro(info)
def atom_gro1() -> AtomGro: info = (1, 'BMIM', 'N1', 1, 4.668, 3.571, 8.232, -0.2489, 0.2514, 0.1046) return AtomGro(info)