Example #1
0
    def project(self, mol):
        """ Project molecule.

        Parameters
        ----------
        mol : :class:`Molecule <htmd.molecule.molecule.Molecule>`
            A :class:`Molecule <htmd.molecule.molecule.Molecule>` object to project.

        Returns
        -------
        data : np.ndarray
            An array containing the projected data.
        """
        mol = mol.copy()
        if len(np.unique(mol.insertion)) > 1:
            mol.renumberResidues()
        ca_indices, nco_indices, proline_indices, chain_ids = self._getSelections(
            mol)
        mol.filter(self.sel, _logger=False)

        xyz = np.swapaxes(np.swapaxes(np.atleast_3d(mol.coords), 1, 2), 0, 1)
        xyz = np.array(xyz.copy(), dtype=np.float32) / 10  # converting to nm

        from mdtraj.geometry._geometry import _dssp as dssp
        natoms = np.unique((nco_indices.shape[0], ca_indices.shape[0],
                            proline_indices.shape[0], chain_ids.shape[0]))
        if len(natoms) != 1:
            raise AssertionError(
                'Wrong dimensions in SS data arrays. Report this bug on the issue tracker.'
            )
        data = dssp(xyz, nco_indices, ca_indices, proline_indices, chain_ids)

        if self.simplified:
            trans = str.maketrans('HGIEBTS ', 'HHHEECCC')
            data = data.translate(trans)

        data = np.fromiter(data, dtype=np.dtype('U2'))
        data = data.reshape(mol.numFrames, len(chain_ids))

        if self.integer:
            if self.simplified:
                data[data == 'H'] = 2
                data[data == 'E'] = 1
                data[data == 'C'] = 0
            else:
                data[data == 'H'] = 3
                data[data == 'B'] = 4
                data[data == 'E'] = 5
                data[data == 'G'] = 6
                data[data == 'I'] = 7
                data[data == 'T'] = 8
                data[data == 'S'] = 9
                data[data == ' '] = 10
            data = np.array(data, dtype=np.int32)
        #data[:, np.logical_not(protein_indices)] = 'NA'

        return data
Example #2
0
    def project(self, mol):
        """ Project molecule.

        Parameters
        ----------
        mol : :class:`Molecule <htmd.molecule.molecule.Molecule>`
            A :class:`Molecule <htmd.molecule.molecule.Molecule>` object to project.

        Returns
        -------
        data : np.ndarray
            An array containing the projected data.
        """
        mol = mol.copy()
        if len(np.unique(mol.insertion)) > 1:
            mol.renumberResidues()
        ca_indices, nco_indices, proline_indices, chain_ids = self._getSelections(mol)
        mol.filter(self.sel, _logger=False)

        xyz = np.swapaxes(np.swapaxes(np.atleast_3d(mol.coords), 1, 2), 0, 1)
        xyz = np.array(xyz.copy(), dtype=np.float32) / 10  # converting to nm

        from mdtraj.geometry._geometry import _dssp as dssp
        natoms = np.unique((nco_indices.shape[0], ca_indices.shape[0], proline_indices.shape[0], chain_ids.shape[0]))
        if len(natoms) != 1:
            raise AssertionError('Wrong dimensions in SS data arrays. Report this bug on the issue tracker.')
        data = dssp(xyz, nco_indices, ca_indices, proline_indices, chain_ids)

        if self.simplified:
            trans = str.maketrans('HGIEBTS ', 'HHHEECCC')
            data = data.translate(trans)

        data = np.fromiter(data, dtype=np.dtype('U2'))
        data = data.reshape(mol.numFrames, len(chain_ids))

        if self.integer:
            if self.simplified:
                data[data == 'H'] = 2
                data[data == 'E'] = 1
                data[data == 'C'] = 0
            else:
                data[data == 'H'] = 3
                data[data == 'B'] = 4
                data[data == 'E'] = 5
                data[data == 'G'] = 6
                data[data == 'I'] = 7
                data[data == 'T'] = 8
                data[data == 'S'] = 9
                data[data == ' '] = 10
            data = np.array(data, dtype=np.int32)
        #data[:, np.logical_not(protein_indices)] = 'NA'

        return data
Example #3
0
    def project(self, *args, **kwargs):
        """ Project molecule.

        Parameters
        ----------
        mol : :class:`Molecule <htmd.molecule.molecule.Molecule>`
            A :class:`Molecule <htmd.molecule.molecule.Molecule>` object to project.

        Returns
        -------
        data : np.ndarray
            An array containing the projected data.
        """
        mol = args[0]

        ca_indices, nco_indices, proline_indices, chain_ids = self._getSelections(
            mol)
        #print(nco_indices)
        #print(ca_indices)
        #print(proline_indices)
        #print(chain_ids)

        xyz = np.swapaxes(np.swapaxes(np.atleast_3d(mol.coords), 1, 2), 0, 1)
        xyz = np.array(xyz.copy(), dtype=np.float32) / 10  # converting to nm

        from mdtraj.geometry._geometry import _dssp as dssp
        data = dssp(xyz, nco_indices, ca_indices, proline_indices, chain_ids)

        if self.simplified:
            trans = str.maketrans('HGIEBTS ', 'HHHEECCC')
            data = data.translate(trans)

        data = np.fromiter(data, dtype=np.dtype('U2'))
        data = data.reshape(mol.numFrames, len(chain_ids))

        if self.integer:
            data[data == 'H'] = 2
            data[data == 'E'] = 1
            data[data == 'C'] = 0
            data = np.array(data, dtype=np.int32)
        #data[:, np.logical_not(protein_indices)] = 'NA'

        return data
    def project(self, mol):
        """Project molecule.

        Parameters
        ----------
        mol : :class:`Molecule <moleculekit.molecule.Molecule>`
            A :class:`Molecule <moleculekit.molecule.Molecule>` object to project.

        Returns
        -------
        data : np.ndarray
            An array containing the projected data.
        """
        mol = mol.copy()
        molprops = self._getMolProp(mol, "all")

        ca_indices = molprops["ca_indices"]
        nco_indices = molprops["nco_indices"]
        proline_indices = molprops["proline_indices"]
        chain_ids = molprops["chain_ids"]

        mol.filter(self.sel, _logger=False)

        xyz = np.swapaxes(np.swapaxes(np.atleast_3d(mol.coords), 1, 2), 0, 1)
        xyz = np.array(xyz.copy(), dtype=np.float32) / 10  # converting to nm

        try:
            from mdtraj.geometry._geometry import _dssp as dssp
        except ImportError:
            raise ImportError(
                "To calculate secondary structure you need to install mdtraj with `conda install mdtraj -c conda-forge`"
            )

        natoms = np.unique((
            nco_indices.shape[0],
            ca_indices.shape[0],
            proline_indices.shape[0],
            chain_ids.shape[0],
        ))
        if len(natoms) != 1:
            raise AssertionError(
                "Wrong dimensions in SS data arrays. Report this bug on the issue tracker."
            )
        data = dssp(xyz, nco_indices, ca_indices, proline_indices, chain_ids)

        if self.simplified:
            trans = str.maketrans("HGIEBTS ", "HHHEECCC")
            data = data.translate(trans)

        data = np.fromiter(data, dtype=np.dtype("U2"))
        data = data.reshape(mol.numFrames, len(chain_ids))

        if self.integer:
            if self.simplified:
                data[data == "H"] = 2
                data[data == "E"] = 1
                data[data == "C"] = 0
            else:
                data[data == "H"] = 3
                data[data == "B"] = 4
                data[data == "E"] = 5
                data[data == "G"] = 6
                data[data == "I"] = 7
                data[data == "T"] = 8
                data[data == "S"] = 9
                data[data == " "] = 10
            data = np.array(data, dtype=np.int32)
        # data[:, np.logical_not(protein_indices)] = 'NA'

        return data