Beispiel #1
0
    def test_init_one_residue(self, molecule_top_bmim: MoleculeTop,
                              residue_bmim: Residue):
        """
        Tests Molecule initialization with only one residue and some basic
        attributes and methods.
        """
        # Wrong residue
        new_residue = Residue(residue_bmim[:-1])
        with pytest.raises(IOError):
            molec = Molecule(molecule_top_bmim, [new_residue])

        molec = Molecule(molecule_top_bmim, [residue_bmim])

        assert len(molec) == len(molecule_top_bmim)
        assert len(molec) == len(residue_bmim)
        assert len(molec) == 25

        assert str(molec) == 'Molecule of BMIM.'

        for atom, atom_top, atom_gro in zip(molec, molecule_top_bmim,
                                            residue_bmim):
            atom_compare = Atom(atom_top, atom_gro)
            assert atom == atom_compare

        for atom, atom_comp in zip(molec, molec.atoms):
            assert atom == atom_comp

        assert molec[-1] == atom_compare
        assert atom_compare != molec[0]
        assert molec.index(atom_compare) == 24
        with pytest.raises(ValueError):
            _ = molec.index(34)  # type: ignore

        assert molec._each_atom_resid == [0] * len(molec)

        assert molec == molec
        assert molec is molec

        copy_mol = molec.copy()
        assert copy_mol == molec
        assert copy_mol is not molec

        assert len(molec.residues) == 1
        assert molec.residues[0] == residue_bmim
        assert molec.residues[0] is not residue_bmim
        assert molec.molecule_top is molecule_top_bmim

        with pytest.raises(NotImplementedError):
            _ = molec + 1  # type: ignore
        with pytest.raises(NotImplementedError):
            _ = 1 + molec  # type: ignore

        for key in dir(molec.molecule_top):
            assert key in dir(molec)
Beispiel #2
0
    def test_init_multi_residue(self, molecule_top_protein: MoleculeTop,
                                residue_protein: List[Residue]):
        """
        Tests Molecule initialization with multiple residues and some basic
        attributes and methods.
        """
        molec = Molecule(molecule_top_protein, residue_protein)

        assert len(molec) == len(molecule_top_protein)
        assert len(molec) == sum(len(res) for res in residue_protein)
        assert len(molec) == 34

        index = 0
        for res in residue_protein:
            for atom_gro in res:
                atom_compare = Atom(molecule_top_protein[index], atom_gro)
                assert molec[index] == atom_compare
                index += 1

        for atom, atom_comp in zip(molec, molec.atoms):
            assert atom == atom_comp

        assert molec[-1] == atom_compare
        assert molec.index(atom_compare) == 33

        assert molec._each_atom_resid == [0, 0, 0, 1, 1, 1, 2, 2, 3,
                                          3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 7,
                                          8, 8, 8, 9, 9, 10, 10, 10, 11, 11,
                                          11, 12, 12]

        assert molec != 0
        assert molec == molec
        assert molec is molec

        assert molec.copy() == molec
        assert molec.copy() is not molec

        assert len(molec.residues) == 13
        for res1, res2 in zip(molec.residues, residue_protein):
            assert res1 == res2
            assert res1 is not res2
        assert molec.molecule_top is molecule_top_protein