def _SetupFiles(model,reference): # create temporary directory tmp_dir_name=tempfile.mkdtemp() dia = 'PDB' for chain in model.chains: if chain.name==" ": raise RuntimeError("One of the chains in the model has no name. Cannot " "calculate CAD score") if len(chain.name) > 1: dia = 'CHARMM' break; for res in chain.residues: if len(res.name) > 3: dia = 'CHARMM' break; io.SavePDB(model, os.path.join(tmp_dir_name, 'model.pdb'), dialect=dia) dia = 'PDB' for chain in reference.chains: if chain.name==" ": raise RuntimeError("One of the chains in the reference has no name. " "Cannot calculate CAD score") if len(chain.name) > 1: dia = 'CHARMM' break; for res in chain.residues: if len(res.name) > 3: dia = 'CHARMM' break; io.SavePDB(reference, os.path.join(tmp_dir_name, 'reference.pdb'),dialect=dia) return tmp_dir_name
def AssignDSSP(ent, pdb_path="", extract_burial_status=False, tmp_dir=None, dssp_bin=None): """ Assign secondary structure states to peptide residues in the structure. This function uses the DSSP command line program. If you already have a DSSP output file and would like to assign the secondary structure states to an entity, use :func:`LoadDSSP`. :param ent: The entity for which the secondary structure should be calculated :type ent: :class:`~ost.mol.EntityHandle` or :class:`~ost.mol.EntityView` :param extract_burial_status: If true, also extract burial status and store as float-property ``relative_solvent_accessibility`` at residue level :param tmp_dir: If set, overrides the default tmp directory of the operating system :param dssp_bin: The path to the DSSP executable :raises: :class:`~ost.settings.FileNotFound` if the dssp executable is not in the path. :raises: :class:`RuntimeError` when dssp is executed with errors """ entity_saved = False # use of mktemp is a safty problem (use mkstemp and provide file handle to # subsequent process pdb_path=tempfile.mktemp(suffix=".pdb",prefix="temp_entity", dir=tmp_dir) io.SavePDB(ent, pdb_path) entity_saved = True #TODO: exception handling (currently errors occuring here # are handled in the parser LoadDSSP) temp_dssp_path=_ExecuteDSSP(pdb_path, dssp_bin) if not os.path.exists(temp_dssp_path): raise RuntimeError('DSSP output file does not exist.') # assign DSSP to entity try: LoadDSSP(temp_dssp_path, ent, extract_burial_status, entity_saved) except Exception as e: # clean up print("Exception in DSSP:", e) _Cleanup(pdb_path, temp_dssp_path, entity_saved) raise RuntimeError(e) # clean up #print pdb_path, temp_dssp_path _Cleanup(pdb_path, temp_dssp_path, entity_saved) return ent
def _SetupFiles(models): # create temporary directory tmp_dir_name=tempfile.mkdtemp() dia = 'PDB' for index, model in enumerate(models): for chain in model.chains: if len(chain.name) > 1: dia = 'CHARMM' break; for res in chain.residues: if len(res.name) > 3: dia = 'CHARMM' break; io.SavePDB(model, os.path.join(tmp_dir_name, 'model%02d.pdb' % (index+1)), dialect=dia) return tmp_dir_name
def _SetupFiles(entity, selection, scratch_dir, max_number_of_atoms): """ Setup files for naccess calculation in temporary directory :param entity: OST entity to calculate surface :param selection: Calculate surface for subset of entity :param scratch_dir: Scratch directory. A subfolder for temporary files is created in there. If not specified, a default directory is used (see :func:`tempfile.mkdtemp`). :param max_number_of_atoms: Max Number of atoms in the entity (i.e. is limited in the default NACCESS version to 50 000) :returns: Tuple containing temporary directory, input filename for naccess and directory of the input file :exception: RuntimeError if selection is not valid or too many atoms """ # create temporary directory tmp_dir_name = "" if scratch_dir != None: tmp_dir_name = tempfile.mkdtemp(dir=scratch_dir) else: tmp_dir_name = tempfile.mkdtemp() # select as specified by user if selection != "": entity_view = entity.Select(selection) else: entity_view = entity if len(entity_view.atoms) > max_number_of_atoms: raise RuntimeError("Too much atoms for NACCESS (> %s)" % max_number_of_atoms) if not entity_view.IsValid(): raise RuntimeError("Could not create view for selection (%s)" % (selection)) # write entity to tmp file tmp_file_name = "entity.pdb" tmp_file_base = os.path.join(tmp_dir_name, "entity") io.SavePDB(entity_view, os.path.join(tmp_dir_name, tmp_file_name)) return (tmp_dir_name, tmp_file_name, tmp_file_base)