Example #1
0
    def testAccNACCESS(self):

        # tests oligo mode by comparing the results from doing the
        # corresponding calculations manually
        ent_one = io.LoadPDB(os.path.join("testfiles", "1a0s.pdb"))
        ent_two = io.LoadPDB(os.path.join("testfiles", "1a0s.pdb"))

        # we're only interested in peptide stuff...
        ent_one = ent_one.Select("peptide=true")
        ent_two = ent_two.Select("peptide=true")

        acc_classic = AccessibilitiesRaw(ent_one)
        acc_oligo = AccessibilitiesOligo(ent_two)

        self.assertTrue(Compare(acc_classic, acc_oligo))

        # if there is naccess around, we also check for equality with
        # naccess results
        try:
            naccess_path = settings.Locate("naccess")
            ent_three = io.LoadPDB(os.path.join("testfiles", "1a0s.pdb"))
            ent_three = ent_three.Select("peptide=true")
            acc_naccess = AccessibilitiesRaw(ent_three, use_naccess=True)
            self.assertTrue(Compare(acc_classic, acc_naccess))
        except:
            print(
                "Could not find NACCESS, could not compare Accessiblity function..."
            )
    def test_CBeta(self):
        # test if the dst residues contain cbeta, unless they are glycines
        tpl = io.LoadPDB('testfiles/cbeta.pdb')
        new_hdl = mol.CreateEntity()
        ed = new_hdl.EditXCS()
        c = ed.InsertChain('A')
        ed.AppendResidue(c, 'MET')
        ed.AppendResidue(c, 'GLY')
        ed.AppendResidue(c, 'GLY')
        ed.AppendResidue(c, 'HIS')
        err, has_cbeta = mol.alg.CopyConserved(tpl.residues[0],
                                               new_hdl.residues[0], ed)
        self.assertTrue(has_cbeta)
        self.assertTrue(err)
        err, has_cbeta = mol.alg.CopyConserved(tpl.residues[1],
                                               new_hdl.residues[1], ed)
        self.assertFalse(has_cbeta)
        self.assertTrue(err)
        err, has_cbeta = mol.alg.CopyConserved(tpl.residues[2],
                                               new_hdl.residues[2], ed)
        self.assertFalse(has_cbeta)
        self.assertTrue(err)
        err, has_cbeta = mol.alg.CopyConserved(tpl.residues[3],
                                               new_hdl.residues[3], ed)
        self.assertTrue(has_cbeta)
        self.assertTrue(err)

        residues = new_hdl.residues
        self.assertEqual(len(residues), 4)
        self.assertTrue(residues[0].FindAtom("CB").IsValid())
        self.assertFalse(residues[1].FindAtom("CB").IsValid())
        self.assertFalse(residues[2].FindAtom("CB").IsValid())
        self.assertTrue(residues[3].FindAtom("CB").IsValid())
    def test_CopyResidue(self):
        tpl = io.LoadPDB('testfiles/cbeta.pdb')
        new_hdl = mol.CreateEntity()
        ed = new_hdl.EditXCS()
        c = ed.InsertChain('A')
        ed.AppendResidue(c, 'MET')
        ed.AppendResidue(c, 'GLY')
        ed.AppendResidue(c, 'GLY')
        ed.AppendResidue(c, 'HIS')
        ed.AppendResidue(c, 'HIS')
        ed.AppendResidue(c, 'GLY')
        ed.AppendResidue(c, 'HIS')
        ed.AppendResidue(c, 'MET')

        # MET to MET
        err = mol.alg.CopyResidue(tpl.residues[0], new_hdl.residues[0], ed)
        self.assertTrue(err)
        #GLY to GLY
        err = mol.alg.CopyResidue(tpl.residues[1], new_hdl.residues[1], ed)
        self.assertTrue(err)
        # GLY to GLY
        err = mol.alg.CopyResidue(tpl.residues[2], new_hdl.residues[2], ed)
        self.assertTrue(err)
        #now we copy a HIS to a HIS
        err = mol.alg.CopyResidue(tpl.residues[3], new_hdl.residues[3], ed)
        self.assertTrue(err)
        # copy a GLY to a HIS
        err, has_cbeta = mol.alg.CopyNonConserved(tpl.residues[1],
                                                  new_hdl.residues[4], ed)
        self.assertFalse(has_cbeta)
        # copy a MET to a GLY
        err = mol.alg.CopyResidue(tpl.residues[0], new_hdl.residues[5], ed)
        self.assertFalse(err)
        # copy a MET to a HIS
        err = mol.alg.CopyResidue(tpl.residues[0], new_hdl.residues[6], ed)
        self.assertFalse(err)
        # copy a GLY to a MET with adding CB
        err = mol.alg.CopyResidue(tpl.residues[1], new_hdl.residues[7], ed)
        self.assertFalse(err)

        residues = new_hdl.residues
        self.assertEqual(len(residues), 8)
        # MET to MET
        self.assertTrue(residues[0].FindAtom("CB").IsValid())
        #GLY to GLY
        self.assertFalse(residues[1].FindAtom("CB").IsValid())
        #now we copy a GLY to a GLY
        self.assertFalse(residues[2].FindAtom("CB").IsValid())
        #now we copy a HIS to a HIS
        self.assertTrue(residues[3].FindAtom("CB").IsValid())
        #now we copy a GLY to a HIS without adding CB
        self.assertFalse(residues[4].FindAtom("CB").IsValid())
        #now we copy a MET to a GLY
        self.assertFalse(residues[5].FindAtom("CB").IsValid())
        # copy a MET to a HIS
        self.assertTrue(residues[6].FindAtom("CB").IsValid())
        # copy a GLY to a MET with adding CB
        self.assertTrue(residues[7].FindAtom("CB").IsValid())
Example #4
0
    def testAccDSSP(self):

        # only relevant if dssp there
        try:
            # same check used in dssp binding
            dssp_path = settings.Locate(['dsspcmbi', 'dssp', 'mkdssp'],
                                        env_name='DSSP_EXECUTABLE')
        except:
            print(
                "Could not find DSSP, could not compare Accessibility function..."
            )
            return

        # we assume oligo mode to be working as it is tested in
        # testAccNACCESS. So we only test the single residue
        # accessibilitities
        ent_one = io.LoadPDB(os.path.join("testfiles", "1a0s.pdb"))
        ent_two = io.LoadPDB(os.path.join("testfiles", "1a0s.pdb"))
        ent_one = ent_one.Select("peptide=true")
        ent_two = ent_two.Select("peptide=true")

        dssp.AssignDSSP(ent_one,
                        extract_burial_status=True,
                        dssp_bin=dssp_path)
        mol.alg.Accessibility(ent_two,
                              algorithm=mol.alg.AccessibilityAlgorithm.DSSP)

        for a, b in zip(ent_one.residues, ent_two.residues):

            # overall accessibility
            if a.HasProp("solvent_accessibility") and b.HasProp("asaAbs"):
                diff = abs(a.GetFloatProp("solvent_accessibility") -\
                           round(b.GetFloatProp("asaAbs")))
                self.assertTrue(diff < 0.01)

            # relative accessibility
            if a.HasProp("relative_solvent_accessibility") and b.HasProp(
                    "asaRel"):
                diff = abs(a.GetFloatProp("relative_solvent_accessibility") -\
                           b.GetFloatProp("asaRel"))
                self.assertTrue(diff < 0.01)
    def testSecStruct(self):

        # unit test only makes sense, when a dssp binary is around
        try:
            # same check used in dssp binding
            dssp_path = settings.Locate(['dsspcmbi', 'dssp', 'mkdssp'],
                                        env_name='DSSP_EXECUTABLE')
        except:
            print(
                "Could not find DSSP, could not compare sec struct assignment..."
            )
            return

        dssp_ent = io.LoadPDB(os.path.join("testfiles", "1a0s.pdb"))
        ost_ent = io.LoadPDB(os.path.join("testfiles", "1a0s.pdb"))

        dssp.AssignDSSP(dssp_ent, dssp_bin=dssp_path)
        mol.alg.AssignSecStruct(ost_ent)

        for a, b in zip(dssp_ent.residues, ost_ent.residues):
            self.assertTrue(
                str(a.GetSecStructure()) == str(b.GetSecStructure()))
Example #6
0
 def testPeptideFilter(self):
   # check that CA only chains are ok and ligand chains are skipped
   ent_1_full = io.LoadPDB(os.path.join("testfiles", "5tglA.pdb"))
   ent_2_full = io.LoadPDB(os.path.join("testfiles", "5tglA_modified.pdb"))
   exp_atom_count = 253
   # check CA-only chain
   ent_1 = ent_1_full.Select("cname=A")
   ent_2 = ent_2_full.Select("cname=A")
   view1, view2 = mol.alg.MatchResidueByLocalAln(ent_1, ent_2)
   self.assertEqual(view1.atom_count, exp_atom_count)
   self.assertEqual(view2.atom_count, exp_atom_count)
   view1, view2 = mol.alg.MatchResidueByGlobalAln(ent_1, ent_2)
   self.assertEqual(view1.atom_count, exp_atom_count)
   self.assertEqual(view2.atom_count, exp_atom_count)
   # check ligand chain
   ent_1_ligand = ent_1_full.Select("cname='_'")
   ent_2_ligand = ent_2_full.Select("cname='_'")
   view1, view2 = mol.alg.MatchResidueByLocalAln(ent_1_ligand, ent_2_ligand)
   self.assertEqual(view1.atom_count, 0)
   self.assertEqual(view2.atom_count, 0)
   view1, view2 = mol.alg.MatchResidueByGlobalAln(ent_1_ligand, ent_2_ligand)
   self.assertEqual(view1.atom_count, 0)
   self.assertEqual(view2.atom_count, 0)
   # check both together
   view1, view2 = mol.alg.MatchResidueByLocalAln(ent_1_full, ent_2_full)
   self.assertEqual(view1.atom_count, exp_atom_count)
   self.assertEqual(view2.atom_count, exp_atom_count)
   view1, view2 = mol.alg.MatchResidueByGlobalAln(ent_1_full, ent_2_full)
   self.assertEqual(view1.atom_count, exp_atom_count)
   self.assertEqual(view2.atom_count, exp_atom_count)
   # try case where local alignment fails
   ev1 = ent_1.Select('rindex<2')   # seq = GI
   ev2 = ent_2.Select('rindex=2:3') # seq = RA
   view1, view2 = mol.alg.MatchResidueByLocalAln(ev1, ev2)
   self.assertEqual(view1.atom_count, 0)
   self.assertEqual(view2.atom_count, 0)
    def test_CBetaFail(self):
        # make sure that we can handle cases where CB reconstruction fails

        # NOTES:
        # - SNN is (since June 2011) labeled as a modified ASN but has a weird
        #   backbone structure without any overlap in atom names with ASN
        #   -> we hence expect it to a) always fall back to CopyNonConserved
        #      and b) fail to copy any atoms (and hence also fail to)
        # - SNN also removes N of following residue which is expected to have an
        #   incomplete backbone which would make it impossible to create a CB pos.

        # source of file: residues A.198 and A.199 from PDB ID 2YHW
        tpl = io.LoadPDB('testfiles/cbeta_fail.pdb')
        new_hdl = mol.CreateEntity()
        ed = new_hdl.EditXCS()
        c = ed.InsertChain('A')
        ed.AppendResidue(c, 'GLY')
        ed.AppendResidue(c, 'ALA')
        ed.AppendResidue(c, 'ASN')
        ed.AppendResidue(c, 'GLY')
        ed.AppendResidue(c, 'ALA')
        # SNN to GLY
        err = mol.alg.CopyResidue(tpl.residues[0], new_hdl.residues[0], ed)
        self.assertFalse(err)
        self.assertEqual(new_hdl.residues[0].atom_count, 0)
        # SNN to ALA
        err = mol.alg.CopyResidue(tpl.residues[0], new_hdl.residues[1], ed)
        self.assertFalse(err)
        self.assertEqual(new_hdl.residues[1].atom_count, 0)
        # SNN to ASN
        err = mol.alg.CopyResidue(tpl.residues[0], new_hdl.residues[2], ed)
        self.assertFalse(err)
        self.assertEqual(new_hdl.residues[2].atom_count, 0)
        # GLY to GLY
        err = mol.alg.CopyResidue(tpl.residues[1], new_hdl.residues[3], ed)
        self.assertTrue(err)
        self.assertEqual(new_hdl.residues[3].atom_count, 3)
        self.assertFalse(new_hdl.residues[3].FindAtom("CB").IsValid())
        # GLY to ALA
        err = mol.alg.CopyResidue(tpl.residues[1], new_hdl.residues[4], ed)
        self.assertFalse(err)
        self.assertEqual(new_hdl.residues[4].atom_count, 3)
        self.assertFalse(new_hdl.residues[4].FindAtom("CB").IsValid())
    def test_fastModified(self):
        # phoshoserine: test if we correctly strip off modifications
        tpl = io.LoadPDB('testfiles/sep.pdb')
        new_hdl = mol.CreateEntity()
        ed = new_hdl.EditXCS()
        c = ed.InsertChain('A')
        ed.AppendResidue(c, 'SER')

        err, has_cbeta = mol.alg.CopyConserved(tpl.residues[0],
                                               new_hdl.residues[0], ed)
        self.assertTrue(err)
        self.assertTrue(has_cbeta)
        residues = new_hdl.residues
        self.assertEqual(len(residues), 1)
        self.assertEqual(len(residues[0].atoms), 6)
        self.assertTrue(new_hdl.FindAtom("A", mol.ResNum(1), "N").IsValid())
        self.assertTrue(new_hdl.FindAtom("A", mol.ResNum(1), "CA").IsValid())
        self.assertTrue(new_hdl.FindAtom("A", mol.ResNum(1), "C").IsValid())
        self.assertTrue(new_hdl.FindAtom("A", mol.ResNum(1), "O").IsValid())
        self.assertTrue(new_hdl.FindAtom("A", mol.ResNum(1), "CB").IsValid())
        self.assertTrue(new_hdl.FindAtom("A", mol.ResNum(1), "OG").IsValid())
    def testTempDirWithDot(self):
        # naccess itself has problems with '.' in the path. So we need to test
        # that it works when data is used which has a correpsonding path.
        na_tmp_dir = tempfile.mkdtemp(prefix="ih.")

        def cleanup():
            shutil.rmtree(na_tmp_dir)

        self.addCleanup(cleanup)
        ost_ent = io.LoadPDB('testfiles/testprotein.pdb')
        excp_raised = False
        try:
            sasa = naccess.CalculateSurfaceArea(ost_ent,
                                                scratch_dir=na_tmp_dir)
        except:
            excp_raised = True
            raise
        self.assertEqual(excp_raised,
                         False,
                         msg="Naccess raised an " +
                         "exception on a path containing a '.'. This is not " +
                         "supposed to happen.")
Example #10
0
  """
  returns percentage of hydrogen bonds in ent1 that are also present in ent2 in
  the range of 0 to 1.
  
  this function is slow as hell, and could be improved drastically by first
  sorting the hydrogen bond lists by donor residue number.
  """

  hbonds_a=HBondList(ent1, hbplus_bin=hbplus_bin)
  hbonds_b=HBondList(ent2, hbplus_bin=hbplus_bin)
  matching=0
  for a in hbonds_a:
    found=False
    for b in hbonds_b:
      acc_names_match=b.acceptor.name==a.acceptor.name
      don_names_match=b.donor.name==a.donor.name
      don_num=b.donor.residue.number==a.donor.residue.number
      acc_num=b.acceptor.residue.number==a.acceptor.residue.number
      if acc_names_match and don_names_match and acc_num and don_num:
        found=True
        break
    if found:
      matching+=1
  if len(hbonds_a)>0:
    return float(matching)/len(hbonds_a)
  else:
    return 0.0

if __name__=='__main__':
  print('HBond Score:', HBondScore(io.LoadPDB(sys.argv[1]), 
                                   io.LoadPDB(sys.argv[2])))
Example #11
0
 def Load(self, pdb_id, chains='', calpha_only=False, fault_tolerant=False):
     return io.LoadPDB(self.FilenameForModel(pdb_id, chains),
                       chains,
                       calpha_only=calpha_only,
                       fault_tolerant=fault_tolerant)
Example #12
0
 def setUp(self):
   p=io.IOProfile(dialect='CHARMM')
   self.eh1=io.LoadPDB(os.path.join("testfiles","hbond1.pdb"),profile=p)
   self.eh2=io.LoadPDB(os.path.join("testfiles","hbond2.pdb"),profile=p)
   self.hb_da_dict=mol.alg.hbond.BuildCHARMMHBondDonorAcceptorDict()
def _LoadFile(file_name):
    """Helper to avoid repeating input path over and over."""
    return io.LoadPDB(os.path.join('testfiles', file_name))
Example #14
0
                               delta.x() * 0.5), False)
        self.update()


def App(title='OST Viewer', width=800, height=600):
    """
  """
    import sys
    app = QApplication(sys.argv)
    fmt = QGLFormat()
    fmt.setAlpha(True)
    fmt.setSampleBuffers(True)
    wnd = ThreeDWidget(fmt)
    wnd.resize(width, height)
    wnd.setWindowTitle(title)
    wnd.show()
    app.threed = wnd
    return app


if __name__ == '__main__':
    from ost import io
    # example use
    app = App()
    structure = io.LoadPDB('1crn.pdb')
    obj = gfx.Entity('structure', gfx.HSC, structure)
    obj.SetColor(gfx.YELLOW, 'rtype=H,E')
    obj.SetDetailColor(gfx.RED, 'rtype=H,E')
    gfx.Scene().Add(obj)
    app.exec_()
Example #15
0
 def setUp(self):
   self.comp_lib = conop.GetDefaultLib()
   io.profiles['DEFAULT'].processor = conop.RuleBasedProcessor(self.comp_lib)
   self.ent = io.LoadPDB("sample_test_cleanup.pdb")
   self.ent_no_wat = io.LoadPDB("sample_nowater.pdb")
   self.ent_no_lig = io.LoadPDB("sample_noligands.pdb")