Exemplo n.º 1
0
    def test_methods(self, bf4_molecule: MoleculeTop,
                     bmim_molecule: MoleculeTop):
        """
        Tests simple methods and magic-methods.
        """
        assert isinstance(bf4_molecule[0], AtomTop)
        atom_compare = AtomTop('B1', 'BF4', 1, 0)
        atom_compare.bonds.add(1)
        atom_compare.bonds.add(2)
        atom_compare.bonds.add(3)
        atom_compare.bonds.add(4)
        assert bf4_molecule[0] == atom_compare
        assert len(bf4_molecule) == 5
        assert bf4_molecule == bf4_molecule
        assert bf4_molecule != 1
        assert bf4_molecule != bmim_molecule
        assert bf4_molecule.resname_len_list == [('BF4', 5)]
        assert bmim_molecule.resname_len_list == [('BMIM', 25)]
        for index, atom in enumerate(bf4_molecule):
            assert bf4_molecule.index(atom) == index

        # copy
        copy_mol = bmim_molecule.copy()
        assert copy_mol == bmim_molecule
        for at1, at2 in zip(copy_mol, bmim_molecule):
            assert at1 == at2
            assert at1 is not at2
Exemplo n.º 2
0
    def test_initialization(self):
        """
        Test System initialization with a system with molecules with multiple
        residues.
        """
        fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/system_CG.gro')
        fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/system_CG.gro')
        fitpSDS = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/SDS_AA.itp')
        fitpADN = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/DNA_CG.itp')

        with pytest.raises(IOError):
            _ = System(fgro, fitpSDS)

        empty = System(fgro)
        assert not empty.different_molecules
        with pytest.raises(IOError, match=r'The molecule.*'):
            empty.add_molecule_top(MoleculeTop(fitpSDS))

        bad_dna_top = MoleculeTop(fitpADN)

        for atom in bad_dna_top[98:105]:
            atom.resname = 'DA'
        for atom in bad_dna_top[105:112]:
            atom.resname = 'DG'

        with pytest.raises(IOError, match=r'The sequence.*'):
            empty.add_molecule_top(bad_dna_top)

        empty.add_molecule_top(MoleculeTop(fitpADN))
Exemplo n.º 3
0
    def test_initialization(self, bf4_itp_fname: str):
        """
        Initialization.
        """
        with pytest.raises(ValueError, match=r".*txt.*"):
            molecule = MoleculeTop('test.txt')
        with pytest.raises(ValueError, match=r".*txt.*"):
            molecule = MoleculeTop('test.itp', file_format=".txt")

        # Test with fname and fopen
        for i in range(2):
            if not i:
                molecule = MoleculeTop(bf4_itp_fname)
            else:
                fopen = open(bf4_itp_fname)
                molecule = MoleculeTop(fopen)  # type: ignore
            assert molecule.ftop == bf4_itp_fname
            assert molecule.name == 'BF4'

            atoms_info = [('B1', 'BF4', 1), ('F2', 'BF4', 1), ('F3', 'BF4', 1),
                          ('F4', 'BF4', 1), ('F5', 'BF4', 1)]
            atoms_test = [
                AtomTop(*info, i) for i, info in enumerate(atoms_info)
            ]
            atoms_test[0].connect(atoms_test[1])
            atoms_test[0].connect(atoms_test[2])
            atoms_test[0].connect(atoms_test[3])
            atoms_test[0].connect(atoms_test[4])
            assert molecule.atoms == atoms_test
            assert str(molecule) == 'MoleculeTop of BF4.'
Exemplo n.º 4
0
def molecule_popc_AA() -> Molecule:
    """
    Molecule instance of POPC in all-atom resolution.
    """
    fitppopc = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/popc-AA.itp')
    fgropopc = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/popc-AA.gro')
    popcgro = SystemGro(fgropopc)[0]
    popcitp = MoleculeTop(fitppopc)
    return Molecule(popcitp, [popcgro])
Exemplo n.º 5
0
def molecule_VTE_AA() -> Molecule:
    """
    Molecule instance of E vitamin in all-atom resolution.
    """
    fitpVTE = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/VTE_AA.itp')
    fgroVTE = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/VTE_AA.gro')
    VTEgro = SystemGro(fgroVTE)[0]
    VTEitp = MoleculeTop(fitpVTE)
    return Molecule(VTEitp, [VTEgro])
Exemplo n.º 6
0
    def test_resids(self, bf4_molecule: MoleculeTop):
        """
        Resids access and setter.
        """
        assert bf4_molecule.resids == [1]
        with pytest.raises(ValueError, match='new_resids.*'):
            bf4_molecule.resids = 1  # type: ignore
        with pytest.raises(ValueError, match='Expected.*'):
            bf4_molecule.resids = [0, 23]

        bf4_molecule.resids = [3]
        for atom in bf4_molecule:
            assert atom.resid == 3
        assert bf4_molecule.resids == [3]

        # Multiple resids
        bf4_molecule[0].resid = 8
        assert bf4_molecule.resids == [8, 3]
        bf4_molecule.resids = [56, 88]
        assert bf4_molecule.resids == [56, 88]
Exemplo n.º 7
0
    def test_resnames(self, bf4_molecule: MoleculeTop):
        """
        Resnames access and setter.
        """
        assert bf4_molecule.resnames == ['BF4']
        with pytest.raises(ValueError, match='new_resnames.*'):
            bf4_molecule.resnames = 'test'  # type: ignore
        with pytest.raises(ValueError, match='Expected.*'):
            bf4_molecule.resnames = ['test', 'test2']

        bf4_molecule.resnames = ['BMIM']
        for atom in bf4_molecule:
            assert atom.resname == 'BMIM'
        assert bf4_molecule.resnames == ['BMIM']

        # Multiple resnames
        bf4_molecule[0].resname = 'BF4'
        assert bf4_molecule.resnames == ['BF4', 'BMIM']
        bf4_molecule.resnames = ['Test', 'T2']
        assert bf4_molecule.resnames == ['Test', 'T2']
Exemplo n.º 8
0
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])
Exemplo n.º 9
0
def molecule_VTE_map() -> Molecule:
    """
    Molecule instance of E vitamin in coarse-grained resolution after being
    mapped.
    """
    fitpVTE = os.path.join(ACTUAL_PATH,
                           '../../gaddlemaps/data/vitamin_E_CG.itp')
    fgroVTE = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/VTE_map.gro')
    VTEgro = SystemGro(fgroVTE)[0]
    VTEitp = MoleculeTop(fitpVTE)
    return Molecule(VTEitp, [VTEgro])
Exemplo n.º 10
0
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])
Exemplo n.º 11
0
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])
Exemplo n.º 12
0
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])
Exemplo n.º 13
0
    def test_update_from_top(self, molecule_bmim: Molecule):
        """
        Test for update_from_molecule_top method.
        """
        # Make a copy of the original top
        fname = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BMIM_AA.itp')
        mol_top = MoleculeTop(fname)
        for at1, at2 in zip(mol_top, molecule_bmim):
            assert at1.name == at2.name

        mol_top[1].name = 'test'
        molecule_bmim.update_from_molecule_top(mol_top)
        for at1, at2 in zip(mol_top, molecule_bmim):
            assert at1.name == at2.name
        assert molecule_bmim[1].name == 'test'
Exemplo n.º 14
0
def molecule_top_protein() -> MoleculeTop:
    """
    MoleculeTop instance for molecule with multiple residues.
    """
    fname = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/Protein_CG.itp')
    return MoleculeTop(fname)
Exemplo n.º 15
0
def molecule_top_bmim() -> MoleculeTop:
    """
    BMIM MoleculeTop instance.
    """
    fname = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BMIM_AA.itp')
    return MoleculeTop(fname)
Exemplo n.º 16
0
def bf4_mtop() -> MoleculeTop:
    """
    A BF4 MoleculeTop.
    """
    return MoleculeTop(
        os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BF4_AA.itp'))
Exemplo n.º 17
0
def bmim_molecule() -> MoleculeTop:
    """
    A BF4 MoleculeTop.
    """
    fname = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BMIM_AA.itp')
    return MoleculeTop(fname)
Exemplo n.º 18
0
def bf4_molecule(bf4_itp_fname: str) -> MoleculeTop:
    """
    A BF4 MoleculeTop.
    """
    return MoleculeTop(bf4_itp_fname)