예제 #1
0
파일: dssp.py 프로젝트: Kortemme-Lab/klab
    def compute(self):
        tmp_dir = self.tmp_dir
        if not self.read_only:
            pdb_object = self.pdb.clone()
        else:
            pdb_object = self.pdb  # in general, we should not be modifying the structure in this class
        input_filepath = write_temp_file(tmp_dir, pdb_object.get_content(), ftype = 'w', prefix = 'dssp_')
        output_filepath = write_temp_file(tmp_dir, '', ftype = 'w', prefix = 'dssp_')
        try:
            p = _Popen('.', shlex.split('mkdssp -i {input_filepath} -o {output_filepath}'.format(**locals())))
            if p.errorcode:
                if p.stderr.find('empty protein, or no valid complete residues') != -1:
                    raise MissingAtomException(p.stdout)
                else:
                    raise Exception('An error occurred while calling DSSP:\n%s' % p.stderr)

            self.dssp_output = read_file(output_filepath)
            self.dssp = self.parse_output()
        except MissingAtomException as e:
            os.remove(input_filepath)
            os.remove(output_filepath)
            raise
        except Exception as e:
            os.remove(input_filepath)
            os.remove(output_filepath)
            raise colortext.Exception('%s\n%s' % (str(e), traceback.format_exc()))
        os.remove(input_filepath)
        os.remove(output_filepath)
예제 #2
0
파일: dssp.py 프로젝트: Kortemme-Lab/klab
 def compute(self, chain_id):
     tmp_dir = self.tmp_dir
     pdb_object = self.pdb.clone()  # we are immediately modifying the PDB file by stripping chains so we need to make a copy
     pdb_object.strip_to_chains(chain_id)
     input_filepath = write_temp_file(tmp_dir, pdb_object.get_content(), ftype = 'w', prefix = 'dssp_')
     output_filepath = write_temp_file(tmp_dir, '', ftype = 'w', prefix = 'dssp_')
     try:
         p = _Popen('.', shlex.split('mkdssp -i {input_filepath} -o {output_filepath}'.format(**locals())))
         if p.errorcode:
             if p.stderr.find('empty protein, or no valid complete residues') != -1:
                 raise MissingAtomException(p.stdout)
             else:
                 raise Exception('An error occurred while calling DSSP:\n%s' % p.stderr)
         self.dssp_output[chain_id] = read_file(output_filepath)
         self.dssp[chain_id] = self.parse_output(chain_id)
     except MissingAtomException as e:
         os.remove(input_filepath)
         os.remove(output_filepath)
         raise
     except Exception as e:
         os.remove(input_filepath)
         os.remove(output_filepath)
         raise colortext.Exception('%s\n%s' % (str(e), traceback.format_exc()))
     os.remove(input_filepath)
     os.remove(output_filepath)
예제 #3
0
파일: dssp.py 프로젝트: Kortemme-Lab/klab
    def __init__(self, p, cut_off = 0.25, acc_array = 'Miller', tmp_dir = '/tmp', read_only = False):
        '''This function strips a PDB file to one chain and then runs DSSP on this new file.
           p should be a PDB object (see pdb.py).
        '''
        try:
            _Popen('.', shlex.split('mkdssp --version'))
        except:
            raise colortext.Exception('mkdssp does not seem to be installed in a location declared in the environment path.')

        self.cut_off = cut_off
        self.tmp_dir = tmp_dir
        self.residue_max_acc = residue_max_acc[acc_array]
        self.read_only = read_only
        if not self.read_only:
            self.pdb = p.clone()  # make a local copy in case this gets modified externally
        else:
            self.pdb = p
        self.chain_order = self.pdb.atom_chain_order
        self.dssp_output = None
        self.dssp = {}
        self.compute()
        self.chain_order = [c for c in self.chain_order if c in self.dssp]
        self.dsspb = NestedBunch(self.dssp)