コード例 #1
0
ファイル: chimera.py プロジェクト: Hoecker-Lab/protlego
def get_SCOP_domain(domain):
    """
    :param domain: str. The SCOPe domain to download as pdb
    :return:
    """

    logger.info(f'Attempting to download domain {domain} from the SCOP server')
    url = f'https://scop.berkeley.edu/astral/pdbstyle/ver=2.07&id={domain}&output=text'
    connected = False
    while not connected:
        try:
            response = urllib.request.urlopen(url)
            text = response.read()
        except Exception as e:
            import time
            logger.warning(
                f'Failed to connect to SCOP with error {e}. Sleeping 5s and retrying.'
            )
            time.sleep(5)
            continue
        connected = True
    filepath = string_to_tempfile(text.decode('ascii'), 'pdb')
    logger.info(f"File downloaded as {filepath}")

    return filepath
コード例 #2
0
ファイル: chimera.py プロジェクト: Hoecker-Lab/protlego
def get_FUZZLE_hhs(domain):
    """
    :param domain: str. The domain to download from Fuzzle as hhs

    :return: filepath: path where the file is located.
    """
    logger.info(
        f'Attempting to download hhs file for {domain} from the FUZZLE server')
    url = f'https://fuzzle.uni-bayreuth.de/hhs/scop95_2.07.psi.hhs/{domain}.hhs'
    connected = False
    while not connected:
        try:
            response = urllib.request.urlopen(url)
            text = response.read()
        except Exception as e:
            import time
            logger.warning(
                f'Failed to connect to FUZZLE with error {e}. Sleeping 5s and retrying.'
            )
            time.sleep(5)
            continue
        connected = True
    filepath = string_to_tempfile(text.decode('ascii'), 'hhs')
    logger.info(f"File downloaded as {filepath}")

    return filepath
コード例 #3
0
def opm(pdb, keep=False, keepaltloc="A"):
    """Download a molecule from the OPM.

    Parameters
    ----------
    pdb: str
        The 4-letter PDB code
    keep: bool
        If False, removes the DUM atoms. If True, it keeps them.

    Returns
    -------
    mol: Molecule
        The oriented molecule

    thickness: float or None
        The bilayer thickness (both layers)

    Examples
    --------
    >>> mol, thickness = opm("1z98")
    >>> mol.numAtoms
    7902
    >>> thickness
    28.2
    >>> _, thickness = opm('4u15')
    >>> thickness is None
    True

    """
    import urllib.request
    import re
    from moleculekit.support import string_to_tempfile
    from moleculekit.molecule import Molecule

    response = urllib.request.urlopen(
        f"https://storage.googleapis.com/opm-assets/pdb/{pdb.lower()}.pdb"
    )
    text = response.read()
    tempfile = string_to_tempfile(text.decode("ascii"), "pdb")

    mol = Molecule(tempfile, keepaltloc=keepaltloc)
    if not keep:
        mol.filter("not resname DUM")

    # Assuming the half-thickness is the last word in the matched line
    # REMARK      1/2 of bilayer thickness:   14.1
    tmp = open(tempfile)
    pattern = re.compile("^REMARK.+thickness")

    thickness = None
    for line in tmp:
        if re.match(pattern, line):
            thickness = 2.0 * float(line.split()[-1])
            break
    tmp.close()
    os.unlink(tempfile)

    return mol, thickness
コード例 #4
0
def getRCSBLigandByLigname(ligname, returnMol2=False):
    """
    Returns a SmallMol object of a ligand by its three letter lignane. This molecule is retrieve from RCSB and a mol2
    written. It is possible to return also the mol2 filename.

    Parameters
    ----------
    ligname: str
        The three letter ligand name
    returnMol2: bool
        If True, the mol2 filename is returned

    Returns
    -------
    sm: moleculekit.smallmol.smallmol.SmallMol
        The SmallMol object

    mol2filename: str
        The mol2 filename

    Example
    -------
    >>> from moleculekit.molecule import Molecule
    >>> mol = Molecule('4eiy')
    >>> np.unique(mol.get('resname', 'not protein and not water'))
    array(['CLR', 'NA', 'OLA', 'OLB', 'OLC', 'PEG', 'ZMA'], dtype=object)
    >>> sm = getRCSBLigandByLigname('ZMA')  # doctest: +ELLIPSIS
    SmallMol module...
    >>> sm.numAtoms
    40
    >>> sm, mol2filename = getRCSBLigandByLigname('ZMA', returnMol2=True)
    >>> mol2filename  # doctest: +ELLIPSIS
    '/tmp/tmp....mol2'

    """
    from moleculekit.support import string_to_tempfile
    from moleculekit.smallmol.smallmol import SmallMol
    from moleculekit.rcsb import _getRCSBtext
    from moleculekit.tools.obabel_tools import openbabelConvert

    url = f"https://files.rcsb.org/ligands/view/{ligname}_ideal.sdf"
    sdf_text = _getRCSBtext(url).decode("ascii")
    tempfile = string_to_tempfile(sdf_text, "sdf")
    mol2 = openbabelConvert(tempfile, "sdf", "mol2")

    sm = SmallMol(mol2)
    if returnMol2:
        return sm, mol2

    return sm
コード例 #5
0
    def send(self, command):
        """Send a tcl command to VMD

        Parameters
        ----------
        command : str
            The tcl command which to send
        """
        if self.done:
            return
        # print( command )
        fn = string_to_tempfile(command, "tcl")
        # 		print(fn)

        cc = f"if {{ [ catch {{ source {fn}}} ] }} {{ unlink {fn} }} else {{ unlink {fn} }}\n"
        self.vmd.stdin.write(cc.encode("ascii"))
        self.vmd.stdin.flush()

        while os.path.isfile(fn) and not self.done:
            time.sleep(0.01)