def opm(pdb): """Download a molecule from the OPM. Removes DUM atoms. Parameters ---------- pdb: str The 4-letter PDB code Returns ------- mol: Molecule The oriented molecule thickness: float The bilayer thickness (both layers) Examples -------- >>> mol, thickness = opm("1z98") >>> mol.numAtoms 7902 >>> thickness 28.2 """ from htmd.molecule.support import string_to_tempfile from htmd.molecule.molecule import Molecule # http://opm.phar.umich.edu/pdb/1z98.pdb r = requests.get("http://opm.phar.umich.edu/pdb/{:s}.pdb".format( pdb.lower())) if r.status_code != 200: raise NameError('PDB code not found in the OPM database') tempfile = string_to_tempfile(r.content.decode('ascii'), "pdb") mol = Molecule(tempfile) mol.filter("not resname DUM") # Assuming the half-thickness is the last word in the first line # REMARK 1/2 of bilayer thickness: 14.1 f = open(tempfile) h = f.readline() f.close() os.unlink(tempfile) hs = h.split() thickness = 2.0 * float(hs[-1]) return mol, thickness
def opm(pdb): """Download a molecule from the OPM. Removes DUM atoms. Parameters ---------- pdb: str The 4-letter PDB code Returns ------- mol: Molecule The oriented molecule thickness: float The bilayer thickness (both layers) Examples -------- >>> mol, thickness = opm("1z98") >>> mol.numAtoms 7902 >>> thickness 28.2 """ from htmd.molecule.support import string_to_tempfile from htmd.molecule.molecule import Molecule # http://opm.phar.umich.edu/pdb/1z98.pdb r = requests.get("http://opm.phar.umich.edu/pdb/{:s}.pdb".format(pdb.lower())) if r.status_code != 200: raise NameError('PDB code not found in the OPM database') tempfile = string_to_tempfile(r.content.decode('ascii'), "pdb") mol = Molecule(tempfile) mol.filter("not resname DUM") # Assuming the half-thickness is the last word in the first line # REMARK 1/2 of bilayer thickness: 14.1 f = open(tempfile) h = f.readline() f.close() os.unlink(tempfile) hs = h.split() thickness = 2.0 * float(hs[-1]) return mol, thickness
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: htmd.smallmol.smallmol.SmallMol The SmallMol object mol2filename: str The mol2 filename Example ------- >>> from htmd.molecule.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' """ import requests from htmd.molecule.support import string_to_tempfile from htmd.smallmol.smallmol import SmallMol r = requests.get( "https://files.rcsb.org/ligands/view/{}_ideal.sdf".format(ligname)) sdf_text = r.content.decode('ascii') tempfile = string_to_tempfile(sdf_text, "sdf") mol2 = openbabelConvert(tempfile, 'sdf', 'mol2') sm = SmallMol(mol2) if returnMol2: return sm, mol2 return sm
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: htmd.smallmol.smallmol.SmallMol The SmallMol object mol2filename: str The mol2 filename Example ------- >>> from htmd.molecule.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' """ import requests from htmd.molecule.support import string_to_tempfile from htmd.smallmol.smallmol import SmallMol r = requests.get("https://files.rcsb.org/ligands/view/{}_ideal.sdf".format(ligname)) sdf_text = r.content.decode('ascii') tempfile = string_to_tempfile(sdf_text, "sdf") mol2 = openbabelConvert(tempfile, 'sdf', 'mol2') sm = SmallMol(mol2) if returnMol2: return sm, mol2 return sm
def _getPDB(pdbid): import requests from htmd.molecule.support import string_to_tempfile from htmd.home import home # Try loading it from the pdb data directory tempfile = False localpdb = os.path.join(home(dataDir='pdb'), pdbid.lower() + '.pdb') if os.path.isfile(localpdb): logger.info('Using local copy for {:s}: {:s}'.format(pdbid, localpdb)) filepath = localpdb else: # or the PDB website logger.info('Attempting PDB query for {:s}'.format(pdbid)) r = requests.get('https://files.rcsb.org/download/{}.pdb'.format(pdbid)) if r.status_code == 200: filepath = string_to_tempfile(r.content.decode('ascii'), 'pdb') tempfile = True else: raise NameError('Invalid PDB code') return filepath, tempfile
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 = "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)
def opm(pdb, keep=False, keepaltloc='A'): """Download a molecule from the OPM. Removes DUM atoms. 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 """ from htmd.molecule.support import string_to_tempfile from htmd.molecule.molecule import Molecule # http://opm.phar.umich.edu/pdb/1z98.pdb r = requests.get("http://opm.phar.umich.edu/pdb/{:s}.pdb".format(pdb.lower())) if r.status_code != 200: raise NameError('PDB code not found in the OPM database') tempfile = string_to_tempfile(r.content.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') match = None for line in tmp: if re.match(pattern, line): match = line tmp.close() os.unlink(tempfile) if not match: thickness = None else: split_line = match.split() thickness = 2.0 * float(split_line[-1]) return mol, thickness
def opm(pdb, keep=False, keepaltloc='A'): """Download a molecule from the OPM. Removes DUM atoms. 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 """ from htmd.molecule.support import string_to_tempfile from htmd.molecule.molecule import Molecule # http://opm.phar.umich.edu/pdb/1z98.pdb r = requests.get("http://opm.phar.umich.edu/pdb/{:s}.pdb".format( pdb.lower())) if r.status_code != 200: raise NameError('PDB code not found in the OPM database') tempfile = string_to_tempfile(r.content.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') match = None for line in tmp: if re.match(pattern, line): match = line tmp.close() os.unlink(tempfile) if not match: thickness = None else: split_line = match.split() thickness = 2.0 * float(split_line[-1]) return mol, thickness