Exemplo n.º 1
0
 def test_preparationData(self):
     from moleculekit.tools.preparation import proteinPrepare
     m = Molecule("3ptb")
     mp, dp = proteinPrepare(m, returnDetails=True)
     hb = dp.findHbonds()
     d = dp.data
     d.loc[d.resid == 40, 'forced_protonation'] = 'HIP'
     mp2, dp2 = dp.reprepare()
     hb2 = dp2.findHbonds()
Exemplo n.º 2
0
def prepareProteinForAtomtyping(mol,
                                guessBonds=True,
                                protonate=True,
                                pH=7,
                                segment=True,
                                verbose=True):
    """ Prepares a Molecule object for atom typing.

    Parameters
    ----------
    mol : Molecule object
        The protein to prepare
    guessBonds : bool
        Drops the bonds in the molecule and guesses them from scratch
    protonate : bool
        Protonates the protein for the given pH and optimizes hydrogen networks
    pH : float
        The pH for protonation
    segment : bool
        Automatically guesses the segments of a protein by using the guessed bonds
    verbose : bool
        Set to False to turn of the printing

    Returns
    -------
    mol : Molecule object
        The prepared Molecule
    """
    mol = mol.copy()
    protsel = mol.atomselect('protein')

    if not np.any(protsel):
        raise RuntimeError('No protein atoms found in Molecule')

    if np.any(~protsel):
        resnames = np.unique(mol.resname[~protsel])
        raise RuntimeError(
            'Found non-protein atoms with resnames {} in the Molecule. Please make sure to only pass protein atoms.'
            .format(resnames))

    if protonate:
        from moleculekit.tools.preparation import proteinPrepare
        mol = proteinPrepare(mol,
                             pH=pH,
                             verbose=verbose,
                             _loggerLevel='INFO' if verbose else 'ERROR')

    if guessBonds:
        mol.bonds = mol._guessBonds()

    if segment:
        from moleculekit.tools.autosegment import autoSegment2
        mol = autoSegment2(mol, fields=('segid', 'chain'), _logger=verbose)
    return mol
Exemplo n.º 3
0
def protonate_mol(inputmolfile: str) -> Molecule:
    """
    Loads, filters the object to chain A and protonates the selection.
    It then writes the filtered protonated pdb out.
    :param inputmolfile: path to the pdb file
    :return: the Molecule object
    """
    mol1 = Molecule(inputmolfile)
    mol1.filter("protein and chain A")
    mol = proteinPrepare(mol1)
    mol.write(f"{inputmolfile[:-4]}-chainA_protonated.pdb")
    return mol
Exemplo n.º 4
0
    def setUpClass(self):
        from moleculekit.home import home
        from moleculekit.molecule import Molecule
        from moleculekit.tools.preparation import proteinPrepare
        from moleculekit.tools.autosegment import autoSegment

        self.testf = os.path.join(home(), 'test-data', 'test-voxeldescriptors')
        mol = Molecule(os.path.join(self.testf, '3PTB.pdb'))
        mol.filter('protein')
        mol = autoSegment(mol, field='both')
        mol = proteinPrepare(mol)
        mol.bonds = mol._guessBonds()
        self.mol = mol
Exemplo n.º 5
0
    def testWithProteinPrepare(self):
        from moleculekit.tools.preparation import proteinPrepare
        from htmd.builder.solvate import solvate
        # Test with proteinPrepare
        pdbids = ['3PTB']
        # pdbids = ['3PTB', '1A25', '1GZM']  # '1U5U' out because it has AR0 (no parameters)
        for pid in pdbids:
            np.random.seed(1)
            mol = Molecule(pid)
            mol.filter('protein')
            mol = proteinPrepare(mol)
            mol.filter(
                'protein')  # Fix for bad proteinPrepare hydrogen placing
            smol = solvate(mol)
            ffs = defaultFf()
            tmpdir = os.path.join(self.testDir, 'withProtPrep', pid)
            _ = build(smol, ff=ffs, outdir=tmpdir)

            refdir = home(dataDir=join('test-amber-build', 'pp', pid))
            _TestAmberBuild._compareResultFolders(refdir, tmpdir, pid)
Exemplo n.º 6
0
def prepare_protein(chimera: Chimera) -> Molecule:
    """
    Builds a water box around the chimera
    :param chimera:
    :return:
    """
    non_standards = Builder.find_nonstandards(chimera)
    if non_standards:
        raise NotCorrectPDBError(f"PDB presents the non_standards residues {non_standards}."
                                 f" Call remove_residue() or Builder.mutate_nonstandards()"
                                 f" if you wish to minimize.")

    mol = proteinPrepare(chimera)
    if 'AR0' in mol.resname:
        mol.set("resname", "ARG", "resname AR0")
    mol = autoSegment(mol)
    mol.center()
    # D = maxDistance(mol,'all') + 6.0
    # smol=solvate(mol,minmax=[[-D, -D, -D], [D, D, D]])
    return mol
Exemplo n.º 7
0
    def setUpClass(self):
        from moleculekit.molecule import Molecule
        from moleculekit.tools.preparation import proteinPrepare

        self.mol = Molecule("3ptb")

        self.prot = self.mol.copy()
        self.prot.filter("protein")

        self.prot_protonated = self.prot.copy()
        self.prot_protonated = proteinPrepare(self.prot_protonated)

        self.lig = self.mol.copy()
        self.lig.filter("resname BEN")

        self.lig_far = self.lig.copy()
        self.lig_far.moveBy([0, 20, 0])

        self.lig_flat = self.lig.copy()
        self.lig_flat.coords[:, 0, :] = -1.7  # Flatten on x axis
Exemplo n.º 8
0
def prepareProteinForAtomtyping(mol,
                                guessBonds=True,
                                protonate=True,
                                pH=7,
                                segment=True,
                                verbose=True):
    """ Prepares a Molecule object for atom typing.

    Parameters
    ----------
    mol : Molecule object
        The protein to prepare
    guessBonds : bool
        Drops the bonds in the molecule and guesses them from scratch
    protonate : bool
        Protonates the protein for the given pH and optimizes hydrogen networks
    pH : float
        The pH for protonation
    segment : bool
        Automatically guesses the segments of a protein by using the guessed bonds
    verbose : bool
        Set to False to turn of the printing

    Returns
    -------
    mol : Molecule object
        The prepared Molecule
    """
    from moleculekit.tools.autosegment import autoSegment2

    mol = mol.copy()
    if guessBonds:  # Need to guess bonds at the start for atom selection and for autoSegment
        mol.bondtype = np.array([], dtype=object)
        mol.bonds = mol._guessBonds()

    protsel = mol.atomselect('protein')
    metalsel = mol.atomselect('element {}'.format(' '.join(metal_atypes)))
    notallowed = ~(protsel | metalsel)

    if not np.any(protsel):
        raise RuntimeError('No protein atoms found in Molecule')

    if np.any(notallowed):
        resnames = np.unique(mol.resname[notallowed])
        raise RuntimeError(
            'Found atoms with resnames {} in the Molecule which can cause issues with the voxelization. Please make sure to only pass protein atoms and metals.'
            .format(resnames))

    protmol = mol.copy()
    protmol.filter(protsel, _logger=False)
    metalmol = mol.copy()
    metalmol.filter(metalsel, _logger=False)

    if protonate:
        from moleculekit.tools.preparation import proteinPrepare
        if np.all(protmol.segid == '') and np.all(protmol.chain == ''):
            protmol = autoSegment2(
                protmol,
                fields=('segid', 'chain'),
                basename='K',
                _logger=verbose)  # We need segments to prepare the protein
        protmol = proteinPrepare(protmol,
                                 pH=pH,
                                 verbose=verbose,
                                 _loggerLevel='INFO' if verbose else 'ERROR')

    if guessBonds:
        protmol.bonds = protmol._guessBonds()
        # TODO: Should we remove bonds between metals and protein? Should we remove metals before guessing bonds and add them back in? Might crash otherwise?

    if segment:
        protmol = autoSegment2(
            protmol, fields=('segid', 'chain'),
            _logger=verbose)  # Reassign segments after preparation

        # Assign separate segment to the metals just in case pybel takes that into account
        if np.any(protmol.chain == 'Z') or np.any(protmol.segid == 'ME'):
            raise AssertionError(
                'Report this issue on the moleculekit github issue tracker. Too many chains in the protein.'
            )
        metalmol.segid[:] = 'ME'
        metalmol.chain[:] = 'Z'
        metalmol.resid[:] = np.arange(
            metalmol.numAtoms
        ) * 2 + protmol.resid.max(
        ) + 1  # Just in case, let's put a residue gap between the metals so that they are considered separate chains no matter what happens

    mol = protmol.copy()
    mol.append(metalmol)
    return mol