예제 #1
0
def printSequenceFromPdbFile(fn):
    verbosityOriginal = cing.verbosity
    cing.verbosity = cing.verbosityError
    entryId = 'getSequenceFromPdbFile'
    project = Project(entryId)
    project.removeFromDisk()
    project = Project.open(entryId, status='new')
    project.initPDB(pdbFile=fn, convention=IUPAC)
    fastaString = ''
    for res in project.molecule.allResidues():
        # db doesn't always exist.
        fastaString += getDeepByKeysOrDefault(res, defaultPrintChainCode, 'db',
                                              'shortName')
    cing.verbosity = verbosityOriginal
    nTmessage("Sequence from PDB file:")
    nTmessage(fastaString)

    for res in project.molecule.allResidues():
        nTmessageNoEOL(res.shortName)
    nTmessage('')
    cing.verbosity = cing.verbosityError

    project.removeFromDisk()
    del project
    cing.verbosity = verbosityOriginal
예제 #2
0
    def test_Whatif(self):
        #entryId = "1ai0" # Most complex molecular system in any PDB NMR entry
#        entryId = "2hgh" # Small much studied PDB NMR entry; 48 models
#        entryId = "1bus" # Small much studied PDB NMR entry:  5 models of 57 AA.: 285 residues.
        entryId = "1brv" # DEFAULT is not to do more than 2 models because it takes quite a while.
#        entryId = "1brv_cs_pk_2mdl"

#        entryId = "1tgq_1model"
#        pdbConvention = IUPAC
        parseOnly = False # normal is False
        showValues = True
        ranges='cv'
#        ranges='172-177'
#        ranges='6-13,29-45'


        cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() )
        mkdirs( cingDirTmpTest )
        self.failIf(os.chdir(cingDirTmpTest), msg =
            "Failed to change to test directory for files: " + cingDirTmpTest)
        project = Project( entryId )
        if not parseOnly:
            project.removeFromDisk()
            project = Project.open( entryId, status='new' )
            inputArchiveDir = os.path.join(cingDirTestsData, "ccpn")

            ccpnFile = os.path.join(inputArchiveDir, entryId + ".tgz")
            if not os.path.exists(ccpnFile):
                ccpnFile = os.path.join(inputArchiveDir, entryId + ".tar.gz")
                if not os.path.exists(ccpnFile):
                    self.fail("Neither %s or the .tgz exist" % ccpnFile)

            self.assertTrue(project.initCcpn(ccpnFolder = ccpnFile, modelCount=2))
            self.assertFalse(runWhatif(project, ranges=ranges, parseOnly=False))
        else:
            project = Project.open( entryId, status='old' )
#        print project.cingPaths.format()

        project.save()
        if showValues:
            for res in project.molecule.allResidues():
                nTdebug(repr(res))
                whatifResDict = res.getDeepByKeys(WHATIF_STR)
                if not whatifResDict:
                    continue
#                checkIDList = whatifResDict.keys()
                checkIDList = 'RAMCHK'.split()
                for checkID in checkIDList:
                    valueList = whatifResDict.getDeepByKeys(checkID,VALUE_LIST_STR)
                    qualList  = whatifResDict.getDeepByKeys(checkID,QUAL_LIST_STR)
                    nTdebug("%10s valueList: %-80s qualList: %-80s" % ( checkID, valueList, qualList))
        # Do not leave the old CCPN directory laying around since it might get added to by another test.
        if os.path.exists(entryId):
            self.assertFalse(shutil.rmtree(entryId))
예제 #3
0
    def test_Procheck(self):
        cingDirTmpTest = os.path.join(cingDirTmp, getCallerName())
        mkdirs(cingDirTmpTest)
        self.failIf(os.chdir(cingDirTmpTest),
                    msg="Failed to change to test directory for files: " +
                    cingDirTmpTest)

        runAqua = True
        showProcheckResults = False
        #entryId = "1ai0" # Most complex molecular system in any PDB NMR entry
        entryId = "1bus"
        #        entryId = "1brv_1model" # Small much studied PDB NMR entry
        ranges = None

        if entryId.startswith("1brv"):
            ranges = "173-186"

        if entryId.startswith("1ai0"):
            ranges = "2-20"

        if entryId == "2hgh":
            # in the case of 2hgh this is not a problem because the residue numbering doesn't
            # overlap between the chain A protein and chain B RNA.
            ranges = "2-11,13-33,35-54"
            # 1 and 55 are 5' and 3' terminii which are a little looser.
            # 12, and 34 are bases that are not basepaired.
            ranges += ",104-105,115-136,145-190"
            # 106-114 is a loop
            # 137-144 is a loop
            # 191-193 are 3 Zn ions.

    #This leads to a procheck ranges file like:
    #        RESIDUES   2  B   11  B
    #        RESIDUES  13  B   33  B
    #        RESIDUES  35  B   54  B
    #        RESIDUES 104  A  105  A
    #        RESIDUES 115  A  136  A
    #        RESIDUES 145  A  190  A

        cingDirTmpTest = os.path.join(cingDirTmp, getCallerName())
        mkdirs(cingDirTmpTest)
        self.failIf(os.chdir(cingDirTmpTest),
                    msg="Failed to change to test directory for files: " +
                    cingDirTmpTest)

        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')
        cyanaFile = os.path.join(cingDirTestsData, "cyana",
                                 entryId + ".cyana.tgz")
        self.assertTrue(project.initCyana(cyanaFolder=cyanaFile))
        project.molecule.setRanges(ranges)

        project.save()
        self.failIf(
            project.runProcheck(createPlots=True, runAqua=runAqua) is None)

        if showProcheckResults:
            for res in project.molecule.allResidues():
                nTdebug(repr(res) + " " + repr(res.procheck.secStruct))
예제 #4
0
    def testMolgrapRunFromPdbFile(self):
        #        SETUP FIRST
        #        entryId = "1ai0" # Most complex molecular system in any PDB NMR entry
        #        entryId = "1a4d" # Small much studied PDB NMR entry
        #        entryId = "1zwj" # X-ray entry of CESG interest.
        entryId = "1brv"  # Small much studied PDB NMR entry
        #        entryId = "2hgh_1model"

        # does it matter to import it just now?
        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')
        cyanaFile = os.path.join(cingDirTestsData, "cyana",
                                 entryId + ".cyana.tgz")
        self.assertTrue(project.initCyana(cyanaFolder=cyanaFile))
        project.save()
        gifFileName = entryId + ".gif"
        pathGif = os.path.join(self.cingDirTmpTest, gifFileName)
        self.assertFalse(project.molecule.export2gif(pathGif, project=project))
        self.assertTrue(os.path.exists(pathGif))
        pathMolGifPinup = pathGif[:-4] + '_pin.gif'
        self.assertTrue(os.path.exists(pathMolGifPinup))
        pathGifDefault = os.path.join(cingPythonCingDir, 'PluginCode',
                                      DATA_STR, 'UnknownImage.gif')
        self.assertFalse(
            os.path.getsize(pathGif) == os.path.getsize(pathGifDefault))
        nTmessage("Created new molecular imagery at: %s" % self.cingDirTmpTest)
예제 #5
0
    def test_AddResidue_Standard(self):
        entryId = 'test'
        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')

        mol = Molecule('test')
        project.appendMolecule(mol)
        c = mol.addChain('A')
        r1 = c.addResidue('ALA', 1, Nterminal = True)
        if r1:
            r1.addAllAtoms()
        r2 = c.addResidue('VAL', 2)
        if r2:
            r2.addAllAtoms()
        r2 = c.addResidue('PHE', 3)
        if r2:
            r2.addAllAtoms()
        r2 = c.addResidue('ARG', 4)
        if r2:
            r2.addAllAtoms()
        r3 = c.addResidue('GLU', 5, Cterminal = True)
        if r3:
            r3.addAllAtoms()

        mol.updateAll()

        nTmessage( mol.format() )
예제 #6
0
파일: test_pdb.py 프로젝트: VuisterLab/cing
    def test_pdb(self):

        cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() )
        mkdirs( cingDirTmpTest )
        self.failIf(os.chdir(cingDirTmpTest), msg =
            "Failed to change to test directory for files: " + cingDirTmpTest)

        entryId = "1brv" # Small much studied PDB NMR entry
#        entryId = "tightTurn_IIb"
#        entryId = "1hy8" # small, single model, very low scoring entry

        pdbDirectory = os.path.join(cingDirTestsData,"pdb", entryId)
        pdbFileName = "pdb"+entryId+".ent"
        pdbFilePath = os.path.join( pdbDirectory, pdbFileName)

        # does it matter to import it just now?
        project = Project( entryId )
        self.failIf( project.removeFromDisk())
        project = Project.open( entryId, status='new' )
        project.initPDB( pdbFile=pdbFilePath, convention = IUPAC )

        m = project.molecule
        ranges = 'A.173-178'
        nTdebug("m: %s" % m)
        self.assertTrue( m.toPDB('m001.pdb', model=0, ranges=ranges, convention='XPLOR'))
#        nTdebug("Manual reimport")
#        m.initCoordinates()
#        m.importFromPDB('m001.pdb',convention='XPLOR')
        nTdebug("Reimport 1")
        m.replaceCoordinatesByPdb(pdbFilePath, name = entryId+'_reimport', convention=IUPAC)
#        nTdebug("Reimport 2")
#        m.replaceCoordinatesByPdb(pdbFilePath, name = entryId+'_reimport', useModels = "1", convention=IUPAC)

        self.assertFalse(project.mkMacros())
예제 #7
0
    def testPdbFile(self):
        nTwarning("This test case will take about 5 (+3 for 1v0e) minutes and is recommended to be done before major releases.")
    #        entryId = "1ai0" # Most complex molecular system in any PDB NMR entry
    #        entryId = "1brv" # Small much studied PDB NMR entry
    #        entryId = "2hgh_1model"
#        entryList = "1kr8".split()
#        entryList = "1otz".split() # 61 chains of which one is ' '
#        entryList = "1v0e".split()
#        entryList = "1a4d 1a24 1afp 1ai0 1brv 1bus 1cjg 1hue 1ieh 1iv6 1kr8 1otz 2hgh 2k0e".split()
        entryList = "1a4d 1ai0 1brv 1bus 1hue 1iv6 1kr8".split()
        for entryId in entryList:

            pdbDirectory = os.path.join(cingDirTestsData,"pdb", entryId)
            pdbFileName = "pdb"+entryId+".ent"
            pdbFilePath = os.path.join( pdbDirectory, pdbFileName)

            cingDirTmpTest = os.path.join( cingDirTmp, 'test2_pdb' )
            mkdirs( cingDirTmpTest )
            os.chdir(cingDirTmpTest)
            # does it matter to import it just now?
            project = Project( entryId )
            self.failIf( project.removeFromDisk())
            project = Project.open( entryId, status='new' )
            self.assertTrue( project.initPDB( pdbFile=pdbFilePath, convention=IUPAC, allowNonStandardResidue=True ))
            self.assertTrue( project.save() )
예제 #8
0
파일: test_pdb.py 프로젝트: jakesyl/cing
    def test_pdb(self):

        cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() )
        mkdirs( cingDirTmpTest )
        self.failIf(os.chdir(cingDirTmpTest), msg =
            "Failed to change to test directory for files: " + cingDirTmpTest)

        entryId = "1brv" # Small much studied PDB NMR entry
#        entryId = "tightTurn_IIb"
#        entryId = "1hy8" # small, single model, very low scoring entry

        pdbDirectory = os.path.join(cingDirTestsData,"pdb", entryId)
        pdbFileName = "pdb"+entryId+".ent"
        pdbFilePath = os.path.join( pdbDirectory, pdbFileName)

        # does it matter to import it just now?
        project = Project( entryId )
        self.failIf( project.removeFromDisk())
        project = Project.open( entryId, status='new' )
        project.initPDB( pdbFile=pdbFilePath, convention = IUPAC )

        m = project.molecule
        ranges = 'A.173-178'
        nTdebug("m: %s" % m)
        self.assertTrue( m.toPDB('m001.pdb', model=0, ranges=ranges, convention='XPLOR'))
#        nTdebug("Manual reimport")
#        m.initCoordinates()
#        m.importFromPDB('m001.pdb',convention='XPLOR')
        nTdebug("Reimport 1")
        m.replaceCoordinatesByPdb(pdbFilePath, name = entryId+'_reimport', convention=IUPAC)
#        nTdebug("Reimport 2")
#        m.replaceCoordinatesByPdb(pdbFilePath, name = entryId+'_reimport', useModels = "1", convention=IUPAC)

        self.assertFalse(project.mkMacros())
예제 #9
0
    def test_AddResidue_Standard(self):
        entryId = 'test'
        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')

        mol = Molecule('test')
        project.appendMolecule(mol)
        c = mol.addChain('A')
        r1 = c.addResidue('ALA', 1, Nterminal=True)
        if r1:
            r1.addAllAtoms()
        r2 = c.addResidue('VAL', 2)
        if r2:
            r2.addAllAtoms()
        r2 = c.addResidue('PHE', 3)
        if r2:
            r2.addAllAtoms()
        r2 = c.addResidue('ARG', 4)
        if r2:
            r2.addAllAtoms()
        r3 = c.addResidue('GLU', 5, Cterminal=True)
        if r3:
            r3.addAllAtoms()

        mol.updateAll()

        nTmessage(mol.format())
예제 #10
0
    def testPdbFile(self):
        nTwarning(
            "This test case will take about 5 (+3 for 1v0e) minutes and is recommended to be done before major releases."
        )
        #        entryId = "1ai0" # Most complex molecular system in any PDB NMR entry
        #        entryId = "1brv" # Small much studied PDB NMR entry
        #        entryId = "2hgh_1model"
        #        entryList = "1kr8".split()
        #        entryList = "1otz".split() # 61 chains of which one is ' '
        #        entryList = "1v0e".split()
        #        entryList = "1a4d 1a24 1afp 1ai0 1brv 1bus 1cjg 1hue 1ieh 1iv6 1kr8 1otz 2hgh 2k0e".split()
        entryList = "1a4d 1ai0 1brv 1bus 1hue 1iv6 1kr8".split()
        for entryId in entryList:

            pdbDirectory = os.path.join(cingDirTestsData, "pdb", entryId)
            pdbFileName = "pdb" + entryId + ".ent"
            pdbFilePath = os.path.join(pdbDirectory, pdbFileName)

            cingDirTmpTest = os.path.join(cingDirTmp, 'test2_pdb')
            mkdirs(cingDirTmpTest)
            os.chdir(cingDirTmpTest)
            # does it matter to import it just now?
            project = Project(entryId)
            self.failIf(project.removeFromDisk())
            project = Project.open(entryId, status='new')
            self.assertTrue(
                project.initPDB(pdbFile=pdbFilePath,
                                convention=IUPAC,
                                allowNonStandardResidue=True))
            self.assertTrue(project.save())
예제 #11
0
    def test_Procheck(self):
        cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() )
        mkdirs( cingDirTmpTest )
        self.failIf(os.chdir(cingDirTmpTest), msg =
            "Failed to change to test directory for files: " + cingDirTmpTest)

        runAqua = True
        showProcheckResults = False
        #entryId = "1ai0" # Most complex molecular system in any PDB NMR entry
        entryId = "1bus"
#        entryId = "1brv_1model" # Small much studied PDB NMR entry
        ranges = None

        if entryId.startswith("1brv"):
            ranges = "173-186"

        if entryId.startswith("1ai0"):
            ranges = "2-20"

        if entryId == "2hgh":
            # in the case of 2hgh this is not a problem because the residue numbering doesn't
            # overlap between the chain A protein and chain B RNA.
            ranges = "2-11,13-33,35-54"
                # 1 and 55 are 5' and 3' terminii which are a little looser.
                # 12, and 34 are bases that are not basepaired.
            ranges += ",104-105,115-136,145-190"
                # 106-114 is a loop
                # 137-144 is a loop
                # 191-193 are 3 Zn ions.
    #This leads to a procheck ranges file like:
    #        RESIDUES   2  B   11  B
    #        RESIDUES  13  B   33  B
    #        RESIDUES  35  B   54  B
    #        RESIDUES 104  A  105  A
    #        RESIDUES 115  A  136  A
    #        RESIDUES 145  A  190  A


        cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() )
        mkdirs( cingDirTmpTest )
        self.failIf(os.chdir(cingDirTmpTest), msg =
            "Failed to change to test directory for files: " + cingDirTmpTest)

        project = Project( entryId )
        self.failIf( project.removeFromDisk() )
        project = Project.open( entryId, status='new' )
        cyanaFile = os.path.join(cingDirTestsData, "cyana", entryId + ".cyana.tgz")
        self.assertTrue(project.initCyana(cyanaFolder = cyanaFile))
        project.molecule.setRanges(ranges)

        project.save()
        self.failIf(project.runProcheck(createPlots=True, runAqua=runAqua) is None)

        if showProcheckResults:
            for res in project.molecule.allResidues():
                nTdebug(repr(res) +" "+ repr(res.procheck.secStruct))
예제 #12
0
    def _test_HTMLfile(self):
        """
        Create two html files (project and molecule) that have relative links to each other.
        Exercising the machinery in HTMLfile class.
        """
        entryId = "test_HTMLfile"

        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')
        molecule = Molecule(name='moleculeName')
        project.appendMolecule(molecule)
        # initialize project html page
        # per item always set 2 top level attributes:
        project.htmlLocation = (project.path('index.html'), None)
        project.html = HTMLfile(project.htmlLocation[0],
                                project,
                                title='Project')
        nTdebug("project.htmlLocation[0]: %s" % project.htmlLocation[0])
        #create new folders for Molecule/HTML
        htmlPath = project.htmlPath()
        if os.path.exists(htmlPath):
            removedir(htmlPath)
        os.makedirs(htmlPath)
        nTdebug("htmlPath: %s" % htmlPath)

        # initialize molecule html page
        for subdir in htmlDirectories.values():
            project.mkdir(project.molecule.name, moleculeDirectories.html,
                          subdir)

        # NB project.htmlPath is different from project.path
        molecule.htmlLocation = (project.htmlPath('indexMolecule.html'), None)
        nTdebug("molecule.htmlLocation[0]: %s" % molecule.htmlLocation[0])
        molecule.html = HTMLfile(molecule.htmlLocation[0],
                                 project,
                                 title='Molecule ' + molecule.name)

        # nb: destination is a destination obj (eg molecule object) that is to
        # have a html attribute that points to an HTMLfile instance.
        # In the validate.py code, the source argument is the 'main' section in
        # project.html. JFD doesn't understand why.
        project.html.insertHtmlLinkInTag('li',
                                         section=project.html.main,
                                         source=project,
                                         destination=molecule,
                                         text='mol ref',
                                         id=None)
        # rerun for testing.
        _link = project.html.findHtmlLocation(project, molecule, id=None)
        #        self.assertEquals('moleculeName/HTML/indexMolecule.html#_top', link)
        project.html.main('ul', openTag=False)

        for htmlObj in [project.html, molecule.html]:
            self.assertFalse(htmlObj.render())
예제 #13
0
    def testROGscore(self):
        entryId = 'test'
        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')
        molecule = Molecule(name='moleculeName')
        molecule.ensemble = Ensemble(molecule)  # Needed for html.
        project.appendMolecule(molecule)  # Needed for html.

        # Add some crud to prevent warnings/errors later.
        molecule.addChain('top')
        top = molecule.allChains()[0]
        # Disable warnings temporarily
        v = cing.verbosity
        cing.verbosity = verbosityNothing
        for i in range(1 * 10):
            res = top.addResidue(repr(random()), i)
            for j in range(5):
                _atom = res.addAtom(repr(random()), j)
        cing.verbosity = v

        molecule.updateAll()
        project.setupHtml()  # Needed for creating the sub dirs.

        a = Atom(resName='ALA', atomName='HN')
        a.criticize()
        self.assertTrue(a)
        self.assertEquals(a.rogScore.colorLabel, COLOR_ORANGE)
        self.assertEquals(a.rogScore.colorCommentList[0][0], COLOR_ORANGE)
        self.assertEquals(a.rogScore.colorCommentList[0][1],
                          ROGscore.ROG_COMMENT_NO_COOR)
        lotr_remark = 'One ring to rule them all'
        preserved_remark = 'Preserved'
        nowHasEffect_remark = 'Now has effect'
        nowHasEffectToo_remark = 'Now has effect too'
        # Next line will have to wipe out the orange comments.
        a.rogScore.setMaxColor(COLOR_RED, lotr_remark)
        a.rogScore.setMaxColor(COLOR_ORANGE, nowHasEffect_remark)
        a.rogScore.setMaxColor(COLOR_RED, preserved_remark)
        a.rogScore.setMaxColor(COLOR_ORANGE, nowHasEffectToo_remark)
        self.assertEquals(len(a.rogScore.colorCommentList), 5)
        self.assertEquals(a.rogScore.colorCommentList[0][1],
                          ROGscore.ROG_COMMENT_NO_COOR)
        self.assertEquals(a.rogScore.colorCommentList[1][1],
                          nowHasEffect_remark)

        myhtml = HTMLfile('testROGscore.html', project, 'A Test')
        myhtml.main("a main")
        a.rogScore.createHtmlForComments(myhtml.main)

        kw = {}
        a.rogScore.addHTMLkeywords(kw)
        myhtml.main("a", 'or by popup', **kw)
        myhtml.render()
예제 #14
0
    def testROGscore(self):
        entryId = 'test'
        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')
        molecule = Molecule(name='moleculeName')
        molecule.ensemble = Ensemble(molecule) # Needed for html.
        project.appendMolecule(molecule) # Needed for html.

        # Add some crud to prevent warnings/errors later.
        molecule.addChain('top')
        top = molecule.allChains()[0]
        # Disable warnings temporarily
        v = cing.verbosity
        cing.verbosity = verbosityNothing
        for i in range( 1*10):
            res = top.addResidue( repr(random()),i )
            for j in range( 5):
                _atom = res.addAtom( repr(random()),j )
        cing.verbosity = v


        molecule.updateAll()
        project.setupHtml() # Needed for creating the sub dirs.

        a = Atom(resName='ALA', atomName='HN')
        a.criticize()
        self.assertTrue(a)
        self.assertEquals(a.rogScore.colorLabel, COLOR_ORANGE)
        self.assertEquals(a.rogScore.colorCommentList[0][0], COLOR_ORANGE)
        self.assertEquals(a.rogScore.colorCommentList[0][1], ROGscore.ROG_COMMENT_NO_COOR)
        lotr_remark = 'One ring to rule them all'
        preserved_remark = 'Preserved'
        nowHasEffect_remark = 'Now has effect'
        nowHasEffectToo_remark = 'Now has effect too'
        # Next line will have to wipe out the orange comments.
        a.rogScore.setMaxColor(COLOR_RED, lotr_remark)
        a.rogScore.setMaxColor(COLOR_ORANGE, nowHasEffect_remark )
        a.rogScore.setMaxColor(COLOR_RED, preserved_remark)
        a.rogScore.setMaxColor(COLOR_ORANGE, nowHasEffectToo_remark)
        self.assertEquals(len(a.rogScore.colorCommentList), 5)
        self.assertEquals(a.rogScore.colorCommentList[0][1], ROGscore.ROG_COMMENT_NO_COOR)
        self.assertEquals(a.rogScore.colorCommentList[1][1], nowHasEffect_remark)

        myhtml = HTMLfile('testROGscore.html', project, 'A Test')
        myhtml.main("a main")
        a.rogScore.createHtmlForComments(myhtml.main)

        kw = {}
        a.rogScore.addHTMLkeywords(kw)
        myhtml.main("a", 'or by popup', **kw)
        myhtml.render()
예제 #15
0
 def test_GetNextAvailableChainId(self):
     entryId = 'test'
     project = Project(entryId)
     self.failIf(project.removeFromDisk())
     project = Project.open(entryId, status='new')
     molecule = Molecule(name='moleculeName')
     project.appendMolecule(molecule)  # Needed for html.
     chainId = molecule.getNextAvailableChainId()
     self.assertEquals(chainId, Chain.defaultChainId)
     n = 26 * 2 + 10 + 1  # alpha numeric including an extra and lower cased.
     for _c in range(n):
         chainId = molecule.getNextAvailableChainId()
         self.assertTrue(molecule.addChain(chainId))
     nTdebug("Added %d chains to: %s" % (n, format(molecule)))
     self.assertEqual(len(molecule.allChains()), n)
예제 #16
0
 def test_GetNextAvailableChainId(self):
     entryId = 'test'
     project = Project(entryId)
     self.failIf(project.removeFromDisk())
     project = Project.open(entryId, status='new')
     molecule = Molecule(name='moleculeName')
     project.appendMolecule(molecule) # Needed for html.
     chainId = molecule.getNextAvailableChainId()
     self.assertEquals( chainId, Chain.defaultChainId)
     n = 26 * 2 + 10 + 1 # alpha numeric including an extra and lower cased.
     for _c in range(n):
         chainId = molecule.getNextAvailableChainId()
         self.assertTrue( molecule.addChain(chainId))
     nTdebug("Added %d chains to: %s" % (n, molecule.format()))
     self.assertEqual( len(molecule.allChains()), n)
예제 #17
0
파일: utils.py 프로젝트: jakesyl/cing
def printSequenceFromPdbFile(fn):
    verbosityOriginal = cing.verbosity
    cing.verbosity = cing.verbosityError
    entryId = 'getSequenceFromPdbFile'
    project = Project(entryId)
    project.removeFromDisk()
    project = Project.open(entryId, status='new')
    project.initPDB(pdbFile=fn, convention=IUPAC)
    fastaString = ''
    for res in project.molecule.allResidues():
        # db doesn't always exist.
        fastaString += getDeepByKeysOrDefault(res, defaultPrintChainCode, 'db', 'shortName')
    cing.verbosity = verbosityOriginal
    nTmessage("Sequence from PDB file:")
    nTmessage(fastaString)

    for res in project.molecule.allResidues():
        nTmessageNoEOL(res.shortName)
    nTmessage('')
    cing.verbosity = cing.verbosityError

    project.removeFromDisk()
    del project
    cing.verbosity = verbosityOriginal
예제 #18
0
    def _test_HTMLfile(self):

        """
        Create two html files (project and molecule) that have relative links to each other.
        Exercising the machinery in HTMLfile class.
        """
        entryId = "test_HTMLfile"

        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')
        molecule = Molecule(name='moleculeName')
        project.appendMolecule(molecule)
        # initialize project html page
        # per item always set 2 top level attributes:
        project.htmlLocation = (project.path('index.html'), None)
        project.html = HTMLfile(project.htmlLocation[0], project, title = 'Project')
        nTdebug("project.htmlLocation[0]: %s" % project.htmlLocation[0])
        #create new folders for Molecule/HTML
        htmlPath = project.htmlPath()
        if os.path.exists(htmlPath):
            removedir(htmlPath)
        os.makedirs(htmlPath)
        nTdebug("htmlPath: %s" % htmlPath)

        # initialize molecule html page
        for subdir in htmlDirectories.values():
            project.mkdir(project.molecule.name, moleculeDirectories.html, subdir)

        # NB project.htmlPath is different from project.path
        molecule.htmlLocation = (project.htmlPath('indexMolecule.html'), None)
        nTdebug("molecule.htmlLocation[0]: %s" % molecule.htmlLocation[0])
        molecule.html = HTMLfile(molecule.htmlLocation[0], project,
                                  title = 'Molecule ' + molecule.name)

        # nb: destination is a destination obj (eg molecule object) that is to
        # have a html attribute that points to an HTMLfile instance.
        # In the validate.py code, the source argument is the 'main' section in
        # project.html. JFD doesn't understand why.
        project.html.insertHtmlLinkInTag('li', section=project.html.main,
            source=project, destination=molecule, text='mol ref', id=None)
        # rerun for testing.
        _link = project.html.findHtmlLocation(project, molecule, id=None)
#        self.assertEquals('moleculeName/HTML/indexMolecule.html#_top', link)
        project.html.main('ul', openTag=False)

        for htmlObj in [ project.html, molecule.html ]:
            self.assertFalse(htmlObj.render())
예제 #19
0
    def test_shiftx(self):
#        entryId = "1brv" # Small much studied PDB NMR entry
#        entryId = "2hgh_1model"  RNA-protein complex.
        entryId = "1brv"
#        entryId = "1tgq_1model" # withdrawn entry
        cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() )
        mkdirs( cingDirTmpTest )
        self.failIf(os.chdir(cingDirTmpTest), msg =
            "Failed to change to test directory for files: " + cingDirTmpTest)

        project = Project( entryId )
        self.failIf( project.removeFromDisk())
        project = Project.open( entryId, status='new' )
        cyanaFile = os.path.join(cingDirTestsData, "cyana", entryId + ".cyana.tgz")
        self.assertTrue(project.initCyana(cyanaFolder = cyanaFile))
        project.runShiftx()
예제 #20
0
    def setupSimplestProject(self):
        entryId = 'setupSimplestProject'
        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')
        molecule = Molecule(name='moleculeName')
        molecule.ensemble = Ensemble(molecule)  # Needed for html.
        project.appendMolecule(molecule)  # Needed for html.
        c = molecule.addChain('A')
        r1 = c.addResidue('ALA', 1, Nterminal=True)
        if r1:
            r1.addAllAtoms()

        molecule.updateAll()
        project.setupHtml()  # Needed for creating the sub dirs.
        return project
예제 #21
0
    def setupSimplestProject(self):
        entryId = 'setupSimplestProject'
        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')
        molecule = Molecule(name='moleculeName')
        molecule.ensemble = Ensemble(molecule) # Needed for html.
        project.appendMolecule(molecule) # Needed for html.
        c = molecule.addChain('A')
        r1 = c.addResidue('ALA', 1, Nterminal = True)
        if r1:
            r1.addAllAtoms()

        molecule.updateAll()
        project.setupHtml() # Needed for creating the sub dirs.
        return project
예제 #22
0
    def test_xplor_nih(self):
        cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() )
        mkdirs( cingDirTmpTest )
        self.failIf(os.chdir(cingDirTmpTest), msg =
            "Failed to change to test directory for files: " + cingDirTmpTest)

        entryId = "gb1"
        pdbDirectory = os.path.join(cingDirTestsData,"xplor", entryId)
        pdbFileName = entryId+".pdb"
        pdbFilePath = os.path.join( pdbDirectory, pdbFileName)

        project = Project( entryId )
        self.failIf( project.removeFromDisk())
        project = Project.open( entryId, status='new' )
        project.initPDB( pdbFile=pdbFilePath, convention = XPLOR )
#        project.validate(ranges, parseOnly, htmlOnly, doProcheck, doWhatif, doWattos, doTalos)
        project.validate(htmlOnly=True, doProcheck=False, doWhatif=False, doWattos=False, doTalos=False)
        project.save()
예제 #23
0
    def test_shiftx(self):
        #        entryId = "1brv" # Small much studied PDB NMR entry
        #        entryId = "2hgh_1model"  RNA-protein complex.
        entryId = "1brv"
        #        entryId = "1tgq_1model" # withdrawn entry
        cingDirTmpTest = os.path.join(cingDirTmp, getCallerName())
        mkdirs(cingDirTmpTest)
        self.failIf(os.chdir(cingDirTmpTest),
                    msg="Failed to change to test directory for files: " +
                    cingDirTmpTest)

        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')
        cyanaFile = os.path.join(cingDirTestsData, "cyana",
                                 entryId + ".cyana.tgz")
        self.assertTrue(project.initCyana(cyanaFolder=cyanaFile))
        project.runShiftx()
예제 #24
0
    def _testCreateCcpn(self):
        'Disabled test because...'
        cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() )
        mkdirs( cingDirTmpTest )
        self.failIf(os.chdir(cingDirTmpTest), msg =
            "Failed to change to test directory for files: " + cingDirTmpTest)

        for entryId in AllChecks.entryList:
            # Allow pdb files to be of different naming systems for this test.
            project = Project(entryId)
            self.failIf(project.removeFromDisk())
            project = Project.open(entryId, status = 'new')

            cyanaFolder = os.path.join(cingDirTestsData,"cyana", entryId+".cyana.tgz")
            nTdebug("Reading files from: " + cyanaFolder)
            project.initCyana( cyanaFolder)

            project.save()
            nTmessage( "Project: %s" % project)
            ccpnFolder = entryId + "New"
            self.assertTrue(project.saveCcpn(ccpnFolder))
예제 #25
0
    def test_superpose(self):
        pdbConvention = IUPAC
        entryId = "1brv"
#        entryId = "2vb1_simple" # Protein solved by X-ray.

        cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() )
        mkdirs( cingDirTmpTest )
        self.failIf(os.chdir(cingDirTmpTest), msg =
            "Failed to change to test directory for files: " + cingDirTmpTest)

        pdbDirectory = os.path.join(cingDirTestsData,"pdb", entryId)
        pdbFileName = "pdb" + entryId + ".ent"
        pdbFilePath = os.path.join( pdbDirectory, pdbFileName)
        self.failIf( not os.path.exists(pdbFilePath), msg= "Failed to find file: "+pdbFilePath)

        # does it matter to import it just now?
        project = Project( entryId )
        self.failIf( project.removeFromDisk())
        project = Project.open( entryId, status='new' )
        project.initPDB( pdbFile=pdbFilePath, convention = pdbConvention )

        # Compare with molmol on 1brv's 48 models:
#        mean global bb    RMSD:  0.98 +/-  0.40 A  ( 0.10.. 2.19 A)
#        mean global heavy RMSD:  1.75 +/-  0.51 A  ( 0.54.. 3.33 A)
        # Note that in molmol the backbone protein atoms are defined: N, CA, C
        # CING used to include the carbonyl atom

        # using default parameters.
        ens = project.molecule.superpose(backboneOnly=True, includeProtons = False, iterations=2)
        nTdebug( 'ens %s' % ens)
        nTdebug( 'ens.averageModel %s' % ens.averageModel)
        self.assertAlmostEquals( 0.7643199324863148, ens.averageModel.rmsd, 3 )
        # Confirmed to be the 'averaage RMSD to mean: 0.698' in molmol using command
        #    Fit 'to_mean'.
        ens = project.molecule.superpose(backboneOnly=False, includeProtons = False,
                                         iterations=3) # no improvement to do 3 over the default 2 but left in for speed checking.
        nTdebug( 'ens.averageModel %s' % ens.averageModel)
        self.assertAlmostEquals( 0.99383582432002637, ens.averageModel.rmsd, 3 )
예제 #26
0
    def test_superpose(self):
        pdbConvention = IUPAC
        entryId = "1brv"
#        entryId = "2vb1_simple" # Protein solved by X-ray.

        cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() )
        mkdirs( cingDirTmpTest )
        self.failIf(os.chdir(cingDirTmpTest), msg =
            "Failed to change to test directory for files: " + cingDirTmpTest)

        pdbDirectory = os.path.join(cingDirTestsData,"pdb", entryId)
        pdbFileName = "pdb" + entryId + ".ent"
        pdbFilePath = os.path.join( pdbDirectory, pdbFileName)
        self.failIf( not os.path.exists(pdbFilePath), msg= "Failed to find file: "+pdbFilePath)

        # does it matter to import it just now?
        project = Project( entryId )
        self.failIf( project.removeFromDisk())
        project = Project.open( entryId, status='new' )
        project.initPDB( pdbFile=pdbFilePath, convention = pdbConvention )

        # Compare with molmol on 1brv's 48 models:
#        mean global bb    RMSD:  0.98 +/-  0.40 A  ( 0.10.. 2.19 A)
#        mean global heavy RMSD:  1.75 +/-  0.51 A  ( 0.54.. 3.33 A)
        # Note that in molmol the backbone protein atoms are defined: N, CA, C
        # CING used to include the carbonyl atom

        # using default parameters.
        ens = project.molecule.superpose(backboneOnly=True, includeProtons = False, iterations=2)
        nTdebug( 'ens %s' % ens)
        nTdebug( 'ens.averageModel %s' % ens.averageModel)
        self.assertAlmostEquals( 0.7643199324863148, ens.averageModel.rmsd, 3 )
        # Confirmed to be the 'averaage RMSD to mean: 0.698' in molmol using command
        #    Fit 'to_mean'.
        ens = project.molecule.superpose(backboneOnly=False, includeProtons = False,
                                         iterations=3) # no improvement to do 3 over the default 2 but left in for speed checking.
        nTdebug( 'ens.averageModel %s' % ens.averageModel)
        self.assertAlmostEquals( 0.99383582432002637, ens.averageModel.rmsd, 3 )
예제 #27
0
    def test_xplor_nih(self):
        cingDirTmpTest = os.path.join(cingDirTmp, getCallerName())
        mkdirs(cingDirTmpTest)
        self.failIf(os.chdir(cingDirTmpTest),
                    msg="Failed to change to test directory for files: " +
                    cingDirTmpTest)

        entryId = "gb1"
        pdbDirectory = os.path.join(cingDirTestsData, "xplor", entryId)
        pdbFileName = entryId + ".pdb"
        pdbFilePath = os.path.join(pdbDirectory, pdbFileName)

        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')
        project.initPDB(pdbFile=pdbFilePath, convention=XPLOR)
        #        project.validate(ranges, parseOnly, htmlOnly, doProcheck, doWhatif, doWattos, doTalos)
        project.validate(htmlOnly=True,
                         doProcheck=False,
                         doWhatif=False,
                         doWattos=False,
                         doTalos=False)
        project.save()
예제 #28
0
    def _testCreateCcpn(self):
        'Disabled test because...'
        cingDirTmpTest = os.path.join(cingDirTmp, getCallerName())
        mkdirs(cingDirTmpTest)
        self.failIf(os.chdir(cingDirTmpTest),
                    msg="Failed to change to test directory for files: " +
                    cingDirTmpTest)

        for entryId in AllChecks.entryList:
            # Allow pdb files to be of different naming systems for this test.
            project = Project(entryId)
            self.failIf(project.removeFromDisk())
            project = Project.open(entryId, status='new')

            cyanaFolder = os.path.join(cingDirTestsData, "cyana",
                                       entryId + ".cyana.tgz")
            nTdebug("Reading files from: " + cyanaFolder)
            project.initCyana(cyanaFolder)

            project.save()
            nTmessage("Project: %s" % project)
            ccpnFolder = entryId + "New"
            self.assertTrue(project.saveCcpn(ccpnFolder))
예제 #29
0
    def testMolgrapRunFromPdbFile(self):
#        SETUP FIRST
#        entryId = "1ai0" # Most complex molecular system in any PDB NMR entry
#        entryId = "1a4d" # Small much studied PDB NMR entry
#        entryId = "1zwj" # X-ray entry of CESG interest.
        entryId = "1brv" # Small much studied PDB NMR entry
#        entryId = "2hgh_1model"

        # does it matter to import it just now?
        project = Project( entryId )
        self.failIf( project.removeFromDisk())
        project = Project.open( entryId, status='new' )
        cyanaFile = os.path.join(cingDirTestsData, "cyana", entryId + ".cyana.tgz")
        self.assertTrue(project.initCyana(cyanaFolder = cyanaFile))
        project.save()
        gifFileName = entryId+".gif"
        pathGif = os.path.join( self.cingDirTmpTest, gifFileName)
        self.assertFalse(project.molecule.export2gif(pathGif, project=project))
        self.assertTrue(os.path.exists(pathGif))
        pathMolGifPinup = pathGif[:-4] + '_pin.gif'
        self.assertTrue(os.path.exists(pathMolGifPinup))
        pathGifDefault =  os.path.join( cingPythonCingDir, 'PluginCode', DATA_STR, 'UnknownImage.gif' )
        self.assertFalse(os.path.getsize(pathGif) == os.path.getsize(pathGifDefault))
        nTmessage("Created new molecular imagery at: %s" % self.cingDirTmpTest)
예제 #30
0
def main(entryId, *extraArgList):
    """inputDir may be a directory or a url. A url needs to start with http://.
    """

    fastestTest = True  # default: False
    #    ranges=AUTO_STR # default is None retrieved from DBMS csv files.
    htmlOnly = False  # default: False but enable it for faster runs without some actual data.
    doWhatif = True  # disables whatif actual run
    doProcheck = True
    doWattos = True
    doTalos = True
    tgzCing = True  # default: True # Create a tgz for the cing project. In case of a CING project input it will be overwritten.
    modelCount = None  # default setting is None
    if fastestTest:
        modelCount = 3
        htmlOnly = True
        doWhatif = False
        doProcheck = False
        doWattos = False
        doTalos = False
    force_redo = True
    force_retrieve_input = True

    nTmessage(header)
    nTmessage(getStartMessage())

    expectedArgumentList = [
        'inputDir', 'outputDir', 'pdbConvention', 'restraintsConvention',
        'archiveType', 'projectType', 'storeCING2db'
    ]
    expectedNumberOfArguments = len(expectedArgumentList)
    if len(extraArgList) != expectedNumberOfArguments:
        nTerror("Got arguments: " + repr(extraArgList))
        nTerror("Failed to get expected number of arguments: %d got %d" %
                (expectedNumberOfArguments, len(extraArgList)))
        nTerror("Expected arguments: %s" % expectedArgumentList)
        return True

    entryCodeChar2and3 = entryId[1:3]

    inputDir = extraArgList[0]
    outputDir = os.path.join(extraArgList[1], DATA_STR, entryCodeChar2and3,
                             entryId)
    pdbConvention = extraArgList[2]  #@UnusedVariable
    restraintsConvention = extraArgList[3]
    archiveType = extraArgList[4]
    projectType = extraArgList[5]
    storeCING2db = False
    if len(extraArgList) >= expectedNumberOfArguments:
        storeCING2db = extraArgList[6]

    if archiveType == ARCHIVE_TYPE_FLAT:
        pass
        # default
    elif archiveType == ARCHIVE_TYPE_BY_ENTRY:
        inputDir = os.path.join(inputDir, entryId)
    elif archiveType == ARCHIVE_TYPE_BY_CH23:
        inputDir = os.path.join(inputDir, entryCodeChar2and3)
    elif archiveType == ARCHIVE_TYPE_BY_CH23_BY_ENTRY:
        inputDir = os.path.join(inputDir, entryCodeChar2and3, entryId)

    ranges = None
    #    targetId = getTargetForFullEntryName(entryId)
    #    if not targetId:
    #        nTerror("Failed to getTargetForFullEntryName for entryId: %s" % entryId)
    #        return True
    #    ranges = getRangesForTarget(targetId)
    #    if ranges == None:
    #        nTerror("Failed to getRangesForTarget for targetId: %s" % targetId)
    #        return True

    nTdebug("Using:")
    nTdebug("inputDir:             %s" % inputDir)
    nTdebug("outputDir:            %s" % outputDir)
    nTdebug("pdbConvention:        %s" % pdbConvention)
    nTdebug("restraintsConvention: %s" % restraintsConvention)
    nTdebug("archiveType:          %s" % archiveType)
    nTdebug("projectType:          %s" % projectType)
    nTdebug("modelCount:           %s" % modelCount)
    nTdebug("storeCING2db:         %s" % storeCING2db)
    nTdebug("ranges:               %s" % ranges)
    # presume the directory still needs to be created.
    cingEntryDir = entryId + ".cing"

    if os.path.isdir(cingEntryDir):
        if force_redo:
            nTmessage("Enforcing a redo")
            rmtree(cingEntryDir)
        else:
            mainIndexFile = os.path.join(cingEntryDir, "index.html")
            isDone = os.path.isfile(mainIndexFile)
            if isDone:
                nTmessage("SKIPPING ENTRY ALREADY DONE")
                return
            nTmessage("REDOING BECAUSE VALIDATION CONSIDERED NOT DONE.")
            rmtree(cingEntryDir)
        # end if.
    # end if.

    os.chdir(outputDir)

    project = Project(entryId)
    if project.removeFromDisk():
        nTerror("Failed to remove existing project (if present)")
        return True
    # end if.

#    extension = '.tgz'
    formatFileName = '%s.tgz'
    #    fileNameTgz = entryId + '.tgz'
    if projectType == PROJECT_TYPE_CING:
        #        fileNameTgz = entryId + '.cing.tgz'
        formatFileName = '%s.cing.tgz'
    elif projectType == PROJECT_TYPE_PDB:
        formatFileName = 'pdb%s.ent.gz'
    fileNameTgz = formatFileName % entryId

    #    nTdebug("fileNameTgz: %s" % fileNameTgz)
    # if true will do retrieveTgzFromUrl.
    if inputDir.startswith("http") or inputDir.startswith("file"):
        stillToRetrieve = False
        if os.path.exists(fileNameTgz):
            if force_retrieve_input:
                os.unlink(fileNameTgz)
                stillToRetrieve = True
            # end if
        else:
            stillToRetrieve = True
        # end if
        if stillToRetrieve:
            retrieveTgzFromUrl(entryId,
                               inputDir,
                               archiveType=archiveType,
                               formatFileName=formatFileName)
        # end if
        if not os.path.exists(fileNameTgz):
            nTerror("Tgz should already have been present skipping entry")
            return
        # end if
    # end if.
#            retrieveTgzFromUrl(entryId, inputDir)

    if projectType == PROJECT_TYPE_CING:
        # Needs to be copied because the open method doesn't take a directory argument..
        fullFileNameTgz = os.path.join(inputDir, fileNameTgz)
        shutil.copy(fullFileNameTgz, '.')
        project = Project.open(entryId, status='old')
        if not project:
            nTerror("Failed to init old project")
            return True
    elif projectType == PROJECT_TYPE_CCPN:
        project = Project.open(entryId, status='new')
        if not project.initCcpn(ccpnFolder=fileNameTgz, modelCount=modelCount):
            nTerror("Failed to init project from ccpn")
            return True
    elif projectType == PROJECT_TYPE_PDB:
        project = Project.open(entryId, status='new')
        #        pdbFileFormats = [ entryId + ".pdb", "pdb" + entryId + ".ent.gz" ]
        #        for pdbFileName in pdbFileFormats:
        #        pdbFileName = "pdb" + entryId + ".ent.gz"
        #        #    pdbFilePath = os.path.join( inputDir, pdbFileName)
        #            pdbFilePath = os.path.join(inputDir, pdbFileName)
        #            if os.path.exists(pdbFilePath):
        #                break
        #        tmpPdbFile = None
        #        if pdbFileName.endswith('.gz'):
        pdbFilePath = entryId + ".pdb"
        #        tmpPdbFile = pdbFilePath
        #        if os.path.exists(pdbFilePath):
        #            os.unlink(pdbFilePath)
        gunzip(fileNameTgz, outputFileName=pdbFilePath, removeOriginal=True)
        project.initPDB(pdbFile=pdbFilePath,
                        convention=IUPAC,
                        nmodels=modelCount)
        #        if tmpPdbFile:
        if True:
            nTdebug("Removing tmp: %s" % pdbFilePath)
            os.unlink(pdbFilePath)


#    if inputDirOrg == inputDirCASD_NMR:
#    if True: # Default is False for this is specific to CASD-NMR
#        nTmessage("Renaming molecule name to entry id: %s" % entryId)
#        project.molecule.name = entryId # insufficient since all data is already initialized to disk.
#        project.updateProject()
#        project.molecule.rename( entryId )

#    project.save()
#    project.molecule.ranges = ranges # JFD: this doesn't seem to be set there exactly.
    project.molecule.superpose(ranges=ranges)
    if True:
        if project.validate(htmlOnly=htmlOnly,
                            ranges=ranges,
                            doProcheck=doProcheck,
                            doWhatif=doWhatif,
                            doWattos=doWattos,
                            doTalos=doTalos):
            nTerror("Failed to validate project read")
            return True

    if storeCING2db:
        # Does require:
        #from cing.PluginCode.sqlAlchemy import csqlAlchemy
        # and should never crash  run.
        try:
            if doStoreCING2db(entryId, ARCHIVE_CASP_ID, project=project):
                nTerror(
                    "Failed to store CING project's data to DB but continuing."
                )
        except:
            nTtracebackError()
            nTerror(
                "Failed to store CING project's data due to above traceback error."
            )

    project.save()
    if projectType == PROJECT_TYPE_CCPN:
        #        fileNameTgz = entryId + '.tgz'
        #        os.unlink(fileNameTgz) # temporary ccpn tgz
        rmdir(entryId)  # temporary ccpn dir

    if tgzCing:
        directoryNameCing = entryId + ".cing"
        tgzFileNameCing = directoryNameCing + ".tgz"
        if os.path.exists(tgzFileNameCing):
            nTwarning("Overwriting: " + tgzFileNameCing)
        cmd = "tar -czf %s %s" % (tgzFileNameCing, directoryNameCing)
        do_cmd(cmd)
예제 #31
0
def plotDihedralD1D2():
    dihedralName1 = 'Cb4N'
    dihedralName2 = 'Cb4C'
    graphicsFormat = "png"

    entryId = "1brv"  # Small much studied PDB NMR entry
    #        entryId = "1hy8" # small, single model, very low scoring entry

    pdbDirectory = os.path.join(cingDirTestsData, "pdb", entryId)
    pdbFileName = "pdb" + entryId + ".ent"
    pdbFilePath = os.path.join(pdbDirectory, pdbFileName)

    # does it matter to import it just now?
    project = Project(entryId)
    project.removeFromDisk()
    project = Project.open(entryId, status='new')
    project.initPDB(pdbFile=pdbFilePath, convention=IUPAC)

    #        ssType = 'E'
    #        resType = 'GLY'
    #        for ssType in histRamaBySsAndResType.keys():
    #            ssTypeForFileName = ssType.replace(' ', '_')
    titleStr = 'd1d2 all resType'
    nTmessage("plotting: %s" % titleStr)
    #            hist = histd1d2BySsAndResType[ssType][resType]

    ps = NTplotSet()  # closes any previous plots
    ps.hardcopySize = (500, 500)

    #                residueName = resType + ""
    x = NTlist(-45, -80, 125)  # outside the range.
    y = NTlist(-65, -63, -125)

    # important to switch to temp space before starting to generate files for the project.
    #        project     = Project('testPlotHistoDihedrald1d2')
    plotparams1 = project.plotParameters.getdefault(dihedralName1,
                                                    'dihedralDefault')
    plotparams2 = project.plotParameters.getdefault(dihedralName2,
                                                    'dihedralDefault')

    x.limit(plotparams1.min, plotparams1.max)
    y.limit(plotparams2.min, plotparams2.max)

    plot = NTplot(title=titleStr,
                  xRange=(plotparams1.min, plotparams1.max),
                  xTicks=range(int(plotparams1.min), int(plotparams1.max + 1),
                               plotparams1.ticksize),
                  xLabel=dihedralName1,
                  yRange=(plotparams2.min, plotparams2.max),
                  yTicks=range(int(plotparams2.min), int(plotparams2.max + 1),
                               plotparams2.ticksize),
                  yLabel=dihedralName2)
    ps.addPlot(plot)

    # Plot a density background
    histList = []
    ssTypeList = hPlot.histd1BySs0.keys(
    )  # TODO: check this histd1BySs0 attribute. UNTESTED.
    ssTypeList.sort()  # in place sort to: space, H, S
    for ssType in ssTypeList:
        hist = getDeepByKeys(hPlot.histd1BySs0, ssType)
        if hist != None:
            nTdebug('appending [%s]' % ssType)
            histList.append(hist)
    if histList:
        plot.dihedralComboPlot(histList)
#            fn = os.path.join('bySsAndResType', ( ssTypeForFileName+"_"+resType+"."+graphicsFormat))
#            fn = os.path.join('byResType', ( resType+"."+graphicsFormat))

    fpGood = open(project.name + '.testCb2Good.out', 'w')
    fpBad = open(project.name + '.testCb2Bad.out', 'w')

    mCount = project.molecule.modelCount

    for res in project.molecule.A.allResidues():
        triplet = NTlist()
        for i in [-1, 0, 1]:
            triplet.append(res.sibling(i))
        if None in triplet:
            nTdebug('Skipping ' % res)

        else:
            ca_atms = triplet.zap('CA')
            cb_atms = triplet.zap('CB')

            nTdebug("%s %s %s %s" % (res, triplet, ca_atms, cb_atms))

            if None in cb_atms:  # skip Gly for now
                nTdebug('Skipping %s' % res)
            else:
                d1 = Dihedral(res, 'Cb4N', range=[0.0, 360.0])
                d1.atoms = [cb_atms[0], ca_atms[0], ca_atms[1], cb_atms[1]]
                d1.calculateValues()
                res['Cb4N'] = d1  # append dihedral to residue

                d2 = Dihedral(res, 'Cb4C', range=[0.0, 360.0])
                d2.atoms = [cb_atms[1], ca_atms[1], ca_atms[2], cb_atms[2]]
                d2.calculateValues()
                res['Cb4C'] = d2  # append dihedral to residue

                bb = getDeepByKeys(res, WHATIF_STR, BBCCHK_STR, VALUE_LIST_STR,
                                   0)  # check first one.
                if bb == None:
                    nTdebug('Skipping without BB %s' % res)
                    continue

                if d1.cv < 0.03 and d2.cv < 0.03:  # Only include structured residues
                    for i in range(mCount):  # Consider each model individually
                        #                    bb = res.Whatif.bbNormality.valueList[i]
                        bb = getDeepByKeys(res, WHATIF_STR, BBCCHK_STR,
                                           VALUE_LIST_STR, i)
                        if bb == None:
                            nTdebug('Skipping without BB %s' % res)
                            continue
                        angles = NTlist()  # store phi, psi, chi1, chi2
                        for angle in ['PHI', 'PSI', 'CHI1', 'CHI2']:
                            if res.has_key(angle):
                                angles.append(res[angle][i])
                            else:
                                angles.append(0.0)
                        #end for
                        if bb < 20.0:  # Arbitrary 20 bb occurences as cuttoff for now
                            fprintf(fpBad,
                                    '%4d   %7.2f  %7.2f  %7.2f  %s  %s %s\n',
                                    res.resNum, d1[i], d2[i], bb,
                                    angles.format("%7.2f  "), res,
                                    res.dssp.consensus)
                        else:
                            fprintf(fpGood,
                                    '%4d   %7.2f  %7.2f  %7.2f  %s  %s %s\n',
                                    res.resNum, d1[i], d2[i], bb,
                                    angles.format("%7.2f  "), res,
                                    res.dssp.consensus)
                #end if
            #end if
        #end if
    #end for
    fpBad.close()
    fpGood.close()

    fn = "allRestype_d1d2." + graphicsFormat
    ps.hardcopy(fn, graphicsFormat)
예제 #32
0
class AllChecks(TestCase):
    'Test case'
    cingDirTmpTest = os.path.join(cingDirTmp, 'test_classes2')
    mkdirs(cingDirTmpTest)
    os.chdir(cingDirTmpTest)

    def __init__(self, *args, **kwds):
        TestCase.__init__(self, *args, **kwds)
        self.project = None
        self.r1 = None
        self.r2 = None
        self.r3 = None
        self.r4 = None
        self.r5 = None
        self.r6 = None
        self.r7 = None
        self.r8 = None

    def createSimpleFastProject(self):
        'create simple fast project'
        entryId = 'test'

        self.project = Project(entryId)
        self.project.removeFromDisk()
        self.project = Project.open(entryId, status='new')

        mol = Molecule('test')
        self.project.appendMolecule(mol)
        c = mol.addChain('A')
        self.r1 = c.addResidue('VAL', 1, Nterminal=True)
        self.r2 = c.addResidue('VAL', 2)
        self.r3 = c.addResidue('GLU', 3)
        self.r4 = c.addResidue('TYR', 4)
        self.r5 = c.addResidue('PHE', 5)
        self.r6 = c.addResidue('GLY', 6)
        self.r7 = c.addResidue('ARG', 7)
        self.r8 = c.addResidue('LEU', 8, Cterminal=True)
        for r in mol.allResidues():
            r.addAllAtoms()
        mol.updateAll()
#        nTmessage( mol.format() )

    def test_simplifyForFcFeature(self):
        'test simplify Specifically For Fc Feature'
        self.createSimpleFastProject()
        _distanceRestraintList = self.project.distances.new(DR_LEVEL,
                                                            status='keep')
        atomPairs = NTlist()
        r1 = self.r1
        r2 = self.r2
        #        r3 = self.r3
        atomPairs.append((r1.MG1, r2.MG1))
        atomPairs.append((r1.MG2, r2.MG1))
        atomPairs.append((r1.MG1, r2.MG2))
        atomPairs.append((r1.MG2, r2.MG2))

        #        atomPairs.append((r2.HN, r2.MG1))
        #        atomPairs.append((r2.HN, r2.MG2))
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
        if distanceRestraint.isValid:
            _distanceRestraintList.append(distanceRestraint)
        else:
            nTerror('Failed to initialize DR with %s' % atomPairs)
#        nTdebug("dr before: %s" % formatall(distanceRestraint))

# Takes 4 simplification iterations.
        self.assertEqual(distanceRestraint.simplifyForFc(),
                         DistanceRestraint.STATUS_SIMPLIFIED)
        #        nTdebug("dr after 1: %s" % formatall(distanceRestraint))
        self.assertEqual(distanceRestraint.simplifyForFc(),
                         DistanceRestraint.STATUS_SIMPLIFIED)
        #        nTdebug("dr after 2: %s" % formatall(distanceRestraint))
        self.assertEqual(distanceRestraint.simplifyForFc(),
                         DistanceRestraint.STATUS_SIMPLIFIED)
        #        nTdebug("dr after 3: %s" % formatall(distanceRestraint))
        self.assertEqual(distanceRestraint.simplifyForFc(),
                         DistanceRestraint.STATUS_NOT_SIMPLIFIED)
        #        nTdebug("dr after 4: %s" % formatall(distanceRestraint)) # don't print as it contains error token.
        _x = "dr after 4: %s" % formatall(distanceRestraint)

    def test_simplifyForFcFeature_2(self):
        'test simplify Specifically For Fc Feature 2'
        # disfunctional as of yet
        self.createSimpleFastProject()
        _distanceRestraintList = self.project.distances.new(DR_LEVEL,
                                                            status='keep')
        atomPairs = NTlist()
        #        r1 = self.r1
        r2 = self.r2
        #        r3 = self.r3
        atomPairs.append((r2.HN, r2.MG1))
        atomPairs.append((r2.MG2, r2.HN))

        #        atomPairs.append((r2.HN, r2.MG1))
        #        atomPairs.append((r2.HN, r2.MG2))
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
        _distanceRestraintList.append(distanceRestraint)
        #        nTdebug("dr before: %s" % formatall(distanceRestraint))

        self.assertEqual(distanceRestraint.simplify(),
                         DistanceRestraint.STATUS_SIMPLIFIED)
#        nTdebug("dr after 1: %s" % formatall(distanceRestraint))

    def test_CombinationToPseudo(self):
        ' test combination to Pseudo'
        self.createSimpleFastProject()

        r1 = self.r1
        r2 = self.r2
        r3 = self.r3
        atomLoL = [
            [r2.HN],
            [r3.HB2, r3.HB3],
            [r3.HB2],
            [r1.HG11, r1.HG12, r1.HG13],
            [r1.HG12, r1.HG11, r1.HG13],
            [r1.HG11, r1.HG12, r1.HG13, r1.HG21, r1.HG22,
             r1.HG23],  # unrepresented by below method.
        ]
        pseudoListResultExpected = [
            None,
            r3.QB,
            None,
            r1.
            MG1,  # TODO: update these to MD1 when CING has IUPAC internally.
            r1.MG1,
            None,
        ]

        i = -1
        for atomList in atomLoL:
            i += 1
            firstAtom = atomList[0]
            self.assertEqual(firstAtom.getRepresentativePseudoAtom(atomList),
                             pseudoListResultExpected[i])

    def test_CombinationToPseudoDouble(self):
        ' test combination to Pseudo Double'
        #        'Simulate 1a24 1254.00     A    3    TYR    QD    A    8    GLN    QG'
        self.createSimpleFastProject()

        e = self.r3  # GLN
        y = self.r4  # TYR
        _distanceRestraintList = self.project.distances.new(DR_LEVEL,
                                                            status='keep')
        atomPairs = NTlist((e.HG2, y.HB2), (e.HG3, y.HB2), (e.HG2, y.HB3),
                           (e.HG3, y.HB3))
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
        #        nTdebug("before: %r" % distanceRestraint  )
        self.assertEqual(distanceRestraint.simplify(),
                         DistanceRestraint.STATUS_SIMPLIFIED)
#        nTdebug("after: %r" % distanceRestraint  )

    def test_CombiToPseudoDouble_2(self):
        'test_CombiToPseudoDouble_2'
        #        'Simulate 1a24 1254.00     A    3    TYR    QD    A    8    GLN    QB'
        self.createSimpleFastProject()

        #        e = self.r3 # GLN
        y = self.r4  # TYR
        _distanceRestraintList = self.project.distances.new(DR_LEVEL,
                                                            status='keep')
        atomPairs = NTlist((y.HE1, y.HB2), (y.HE2, y.HB2), (y.HE1, y.HB3),
                           (y.HE2, y.HB3))
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
        #        nTdebug("before: %r" % distanceRestraint  )
        self.assertEqual(distanceRestraint.simplify(),
                         DistanceRestraint.STATUS_SIMPLIFIED)
#        nTdebug("after: %r" % distanceRestraint  )

    def test_CombiToPseudoQuadruple(self):
        ' test combination to Pseudo 4 some.'
        #        'Simulate 1a24 1254.00     A    3    TYR    QR    A    8    GLN    QB'
        self.createSimpleFastProject()

        y = self.r5  # PHE
        _distanceRestraintList = self.project.distances.new(DR_LEVEL,
                                                            status='keep')
        atomPairs = NTlist((y.QE, y.H), (y.QD, y.H))
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
        #        nTdebug("before: %r" % distanceRestraint  )
        self.assertEqual(distanceRestraint.simplify(),
                         DistanceRestraint.STATUS_NOT_SIMPLIFIED)
#        nTdebug("after: %r" % distanceRestraint  )

    def test_Simplify(self):
        'test Simplify'
        self.createSimpleFastProject()

        y = self.r5  # PHE
        _distanceRestraintList = self.project.distances.new(DR_LEVEL,
                                                            status='keep')
        atomPairs = NTlist((y.QE, y.H), (y.QE, y.H))
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
        #        nTdebug("before: %r" % distanceRestraint  )
        self.assertEqual(distanceRestraint.simplify(),
                         DistanceRestraint.STATUS_NOT_SIMPLIFIED)
#        nTdebug("after: %r" % distanceRestraint  )

    def test_Simplify2(self):
        'test Simplify2'
        _help = """
        For 1a24
        783.00    A    20    PRO    QB    A    23    LEU    MD1   3.20    7.90    2.96    0.56    2.56    3.35    0.32    0.45    0.64    0    0    0
        783.01    A    20    PRO    QB    A    23    LEU    QD    3.20    7.90    2.96    0.56    2.56    3.35    0.32    0.45    0.64    0    0    0
        """
        self.createSimpleFastProject()

        y = self.r5  # PHE
        _distanceRestraintList = self.project.distances.new(DR_LEVEL,
                                                            status='keep')
        atomPairs = NTlist((y.QE, y.H), (y.QE, y.H))
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
        #        nTdebug("before: %r" % distanceRestraint  )
        self.assertEqual(distanceRestraint.simplify(),
                         DistanceRestraint.STATUS_NOT_SIMPLIFIED)
#        nTdebug("after: %r" % distanceRestraint  )

    def test_Simplify3(self):
        'test simplify 3'
        _help = """
        For 1a24
        783.00    A    20    PRO    QB    A    23    LEU    MD1   3.20    7.90    2.96    0.56    2.56    3.35    0.32    0.45    0.64    0    0    0
        783.01    A    20    PRO    QB    A    23    LEU    QD    3.20    7.90    2.96    0.56    2.56    3.35    0.32    0.45    0.64    0    0    0
        """
        self.createSimpleFastProject()

        y = self.r8  # LEU
        _distanceRestraintList = self.project.distances.new(DR_LEVEL,
                                                            status='keep')
        atomPairs = NTlist((y.QD, y.H), (y.MD1, y.H))
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
        #        nTdebug("before: %r" % distanceRestraint  )
        self.assertEqual(distanceRestraint.removeDuplicateAtomPairs2(),
                         DistanceRestraint.STATUS_REMOVED_DUPLICATE)
예제 #33
0
def main(entryId, *extraArgList):
    """inputDir may be a directory or a url. A url needs to start with http://.
    """

    fastestTest = False  # default: False
    htmlOnly = False  # default: False but enable it for faster runs without some actual data.
    doWhatif = True  # disables whatif actual run
    doProcheck = True
    doWattos = True
    doQueeny = True
    doTalos = True
    tgzCing = True  # default: True # Create a tgz for the cing project. In case of a CING project input it will be overwritten.
    # NB leave this set to True or modify code below.
    removeCcpnDirectory = 1  # perhaps not so in the future.
    modelCount = None  # default setting is None
    #    ranges = None

    if fastestTest:
        modelCount = 2  # if this is more and there is only one model present it leads to an error message.
        htmlOnly = True
        doWhatif = False
        doProcheck = False
        doWattos = False
        doQueeny = False
        doTalos = False

    forceRedo = True
    forceRetrieveInput = True

    nTmessage(header)
    nTmessage(getStartMessage())

    # Sync below code with nrgCing#createToposTokens
    expectedArgumentList = """
    verbosity         inputDir             outputDir
    pdbConvention     restraintsConvention archiveType         projectType
    storeCING2db      ranges               filterTopViolations filterVasco
    singleCoreOperation
    """.split()
    expectedNumberOfArguments = len(expectedArgumentList)
    if len(extraArgList) != expectedNumberOfArguments:
        nTmessage(
            "consider updating code to include all sequential parameters: %s" %
            str(expectedArgumentList))
        if len(extraArgList) > expectedNumberOfArguments:
            nTerror("Got arguments: " + str(extraArgList))
            nTerror("Failed to get expected number of arguments: %d got %d" %
                    (expectedNumberOfArguments, len(extraArgList)))
            nTerror("Expected arguments: %s" % expectedArgumentList)
            return True
        # end if
    # end if
    entryCodeChar2and3 = entryId[1:3]
    cing.verbosity = int(extraArgList[IDX_VERBOSITY])
    inputDir = extraArgList[IDX_INPUT]
    outputDir = os.path.join(extraArgList[IDX_OUTPUT], DATA_STR,
                             entryCodeChar2and3, entryId)
    pdbConvention = extraArgList[IDX_PDB]  #@UnusedVariable
    restraintsConvention = extraArgList[IDX_RESTRAINTS]
    archiveType = extraArgList[
        IDX_ARCHIVE]  # Only used for deriving the input location not the output.
    projectType = extraArgList[IDX_PROJECT_TYPE]
    storeCING2db = stringMeansBooleanTrue(
        getDeepByKeysOrAttributes(extraArgList, IDX_STORE_DB))
    ranges = getDeepByKeysOrAttributes(extraArgList, IDX_RANGES)
    filterTopViolations = getDeepByKeysOrAttributes(extraArgList,
                                                    IDX_FILTER_TOP)
    if filterTopViolations:
        filterTopViolations = int(filterTopViolations)  # change '0' to 0
    filterVasco = getDeepByKeysOrAttributes(extraArgList, IDX_FILTER_VASCO)
    if filterVasco:
        filterVasco = int(filterVasco)
    else:
        filterVasco = 1  # Default should be True
    # end if
    singleCoreOperation = getDeepByKeysOrAttributes(extraArgList,
                                                    IDX_SINGLE_CORE_OPERATION)
    if singleCoreOperation:
        singleCoreOperation = int(singleCoreOperation)
    else:
        singleCoreOperation = 0  # Default should be True
    # end if
    if archiveType == ARCHIVE_TYPE_FLAT:
        pass  # default
    elif archiveType == ARCHIVE_TYPE_BY_ENTRY:
        inputDir = os.path.join(inputDir, entryId)
    elif archiveType == ARCHIVE_TYPE_BY_CH23:
        inputDir = os.path.join(inputDir, entryCodeChar2and3)
    elif archiveType == ARCHIVE_TYPE_BY_CH23_BY_ENTRY:
        inputDir = os.path.join(inputDir, entryCodeChar2and3, entryId)

    isRemoteOutputDir = False
    if '@' in outputDir:
        isRemoteOutputDir = True
    # end if
#    vc = vCing('.') # argument is a fake master_ssh_url not needed here.
    archive_id = getArchiveIdFromDirectoryName(outputDir)

    nTdebug("Using program arguments:")
    nTdebug("inputDir:             %s" % inputDir)
    nTdebug("outputDir:            %s" % outputDir)
    nTdebug("pdbConvention:        %s" % pdbConvention)
    nTdebug("restraintsConvention: %s" % restraintsConvention)
    nTdebug("archiveType:          %s" % archiveType)
    nTdebug("projectType:          %s" % projectType)
    nTdebug("storeCING2db:         %s" % storeCING2db)
    nTdebug("ranges:               %s" % ranges)
    nTdebug("filterTopViolations:  %s" % filterTopViolations)
    nTdebug("filterVasco:          %s" % filterVasco)
    nTdebug("singleCoreOperation:  %s" % singleCoreOperation)
    nTdebug("")
    nTdebug("Using derived settings:")
    nTdebug("modelCount:           %s" % modelCount)
    nTdebug("isRemoteOutputDir:    %s" % isRemoteOutputDir)
    nTdebug("archive_id:            %s" % archive_id)

    # For NMR_REDO required as most efficient.
    if singleCoreOperation:
        setToSingleCoreOperation()

    # presume the directory still needs to be created.
    cingEntryDir = entryId + ".cing"

    if os.path.isdir(cingEntryDir):
        if forceRedo:
            nTmessage("Enforcing a redo")
            rmtree(cingEntryDir)
        else:
            mainIndexFile = os.path.join(cingEntryDir, "index.html")
            isDone = os.path.isfile(mainIndexFile)
            if isDone:
                nTmessage("SKIPPING ENTRY ALREADY DONE")
                return
            nTmessage("REDOING BECAUSE VALIDATION CONSIDERED NOT DONE.")
            rmtree(cingEntryDir)
        # end if.
    # end if.

    if isRemoteOutputDir:
        os.chdir(cingDirTmp)
    else:
        os.chdir(outputDir)

    project = Project(entryId)
    if project.removeFromDisk():
        nTerror("Failed to remove existing project (if present)")
        return True
    # end if.

    formatFileName = '%s.tgz'
    if projectType == PROJECT_TYPE_CING:
        formatFileName = '%s.cing.tgz'
    elif projectType == PROJECT_TYPE_PDB:
        formatFileName = 'pdb%s.ent.gz'
    fileNameTgz = formatFileName % entryId

    #    nTdebug("fileNameTgz: %s" % fileNameTgz)
    allowedInputProtocolList = 'http file ssh'.split()
    inputProtocal = string.split(inputDir, ':')[0]
    if inputProtocal in allowedInputProtocolList:
        stillToRetrieve = False
        if os.path.exists(fileNameTgz):
            if forceRetrieveInput:
                os.unlink(fileNameTgz)
                stillToRetrieve = True
            # end if
        else:
            stillToRetrieve = True
        # end if
        if stillToRetrieve:
            retrieveTgzFromUrl(entryId,
                               inputDir,
                               archiveType=archiveType,
                               formatFileName=formatFileName)
        # end if
        if not os.path.exists(fileNameTgz):
            nTerror("Tgz should already have been present skipping entry")
            return
        # end if
    else:
        nTdebug(
            "Entry not retrieved which might be normal in some situations.")
    # end if.

    if projectType == PROJECT_TYPE_CING:
        # Needs to be copied because the open method doesn't take a directory argument..
        #        fullFileNameTgz = os.path.join(inputDir, fileNameTgz)
        #        shutil.copy(fullFileNameTgz, '.')
        project = Project.open(entryId, status='old')
        if not project:
            nTerror("Failed to init old project")
            return True
    elif projectType == PROJECT_TYPE_CCPN:
        project = Project.open(entryId, status='new')
        if not project.initCcpn(ccpnFolder=fileNameTgz, modelCount=modelCount):
            nTerror("Failed to init project from ccpn")
            return True
    elif projectType == PROJECT_TYPE_PDB:
        project = Project.open(entryId, status='new')
        pdbFilePath = entryId + ".pdb"
        gunzip(fileNameTgz, outputFileName=pdbFilePath, removeOriginal=True)
        project.initPDB(pdbFile=pdbFilePath,
                        convention=IUPAC,
                        nmodels=modelCount)
        #        if tmpPdbFile:
        if True:
            nTdebug("Removing tmp: %s" % pdbFilePath)
            os.unlink(pdbFilePath)
    # end if
    if ranges is not None:
        project.molecule.setRanges(ranges)
    # end if
    if archive_id:
        project.molecule.setArchiveId(archive_id)
    # end if
    project.molecule.superpose(ranges=ranges)
    if filterTopViolations and not project.filterHighRestraintViol():
        nTerror("Failed to filterHighRestraintViol")
####> MAIN UTILITY HERE
    if 0:  # DEFAULT 0
        project.save()
    if project.validate(htmlOnly=htmlOnly,
                        ranges=ranges,
                        doProcheck=doProcheck,
                        doWhatif=doWhatif,
                        doWattos=doWattos,
                        doQueeny=doQueeny,
                        doTalos=doTalos,
                        filterVasco=filterVasco):
        nTerror("Failed to validate project read")
        return True
    # end if filterVasco

    # Write a single PDB file containing all models
    # according to IUPAC conventions
    project.export2PDB()

    project.save()

    if storeCING2db and archive_id:
        # Does require:
        #from cing.PluginCode.sqlAlchemy import csqlAlchemy
        # and should never crash  run.
        #        archive_id = ARCHIVE_DEV_NRG_ID
        #        if isProduction:
        #            archive_id = ARCHIVE_NRG_ID
        try:
            if doStoreCING2db(entryId, archive_id, project=project):
                nTerror(
                    "Failed to store CING project's data to DB but continuing."
                )
        except:
            nTtracebackError()
            nTerror(
                "Failed to store CING project's data due to above traceback error."
            )

    if projectType == PROJECT_TYPE_CCPN:
        #        fileNameTgz = entryId + '.tgz'
        os.unlink(fileNameTgz)  # temporary ccpn tgz
        if removeCcpnDirectory:
            rmdir(entryId)  # ccpn dir may contain vasco info.

    if tgzCing:
        directoryNameCing = entryId + ".cing"
        tgzFileNameCing = directoryNameCing + ".tgz"
        if os.path.exists(tgzFileNameCing):
            nTwarning("Overwriting: " + tgzFileNameCing)
        cmd = "tar -czf %s %s" % (tgzFileNameCing, directoryNameCing)
        nTdebug("cmd: %s" % cmd)
        #        do_cmd(cmd)
        status, result = commands.getstatusoutput(cmd)
        if status:
            nTerror("Failed to tar status: %s with result %s" %
                    (status, result))
            return True
        if isRemoteOutputDir:
            if putFileBySsh(tgzFileNameCing, outputDir, ntriesMax=2):
                nTerror(
                    "Failed to send File By Scp status: %s with result %s" %
                    (status, result))
                nTerror("Maintaining results.")
                return True
            # end if
            nTmessage("Removing tgz result: %s" % tgzFileNameCing)
            os.remove(tgzFileNameCing)
            nTmessage("Removing cing dir itself: %s" % directoryNameCing)
            rmdir(directoryNameCing)
        else:  # do NOT remove local copy
            pass
예제 #34
0
def main(entryId, *extraArgList):
    """inputDir may be a directory or a url. A url needs to start with http://.
    """

    fastestTest = False # default: False
    htmlOnly = False # default: False but enable it for faster runs without some actual data.
    doWhatif = True # disables whatif actual run
    doProcheck = True
    doWattos = True
    doQueeny = True
    doTalos = True
    tgzCing = True # default: True # Create a tgz for the cing project. In case of a CING project input it will be overwritten.
                    # NB leave this set to True or modify code below.
    removeCcpnDirectory = 1 # perhaps not so in the future.
    modelCount = None # default setting is None
#    ranges = None

    if fastestTest:
        modelCount = 2 # if this is more and there is only one model present it leads to an error message.
        htmlOnly = True
        doWhatif = False
        doProcheck = False
        doWattos = False
        doQueeny = False
        doTalos = False
        
    forceRedo = True
    forceRetrieveInput = True

    nTmessage(header)
    nTmessage(getStartMessage())

    # Sync below code with nrgCing#createToposTokens
    expectedArgumentList = """
    verbosity         inputDir             outputDir
    pdbConvention     restraintsConvention archiveType         projectType
    storeCING2db      ranges               filterTopViolations filterVasco
    singleCoreOperation
    """.split()
    expectedNumberOfArguments = len(expectedArgumentList)
    if len(extraArgList) != expectedNumberOfArguments:
        nTmessage("consider updating code to include all sequential parameters: %s" % str(expectedArgumentList))
        if len(extraArgList) > expectedNumberOfArguments:
            nTerror("Got arguments: " + str(extraArgList))
            nTerror("Failed to get expected number of arguments: %d got %d" % (
                expectedNumberOfArguments, len(extraArgList)))
            nTerror("Expected arguments: %s" % expectedArgumentList)
            return True
        # end if
    # end if
    entryCodeChar2and3 = entryId[1:3]
    cing.verbosity = int( extraArgList[IDX_VERBOSITY] )
    inputDir = extraArgList[IDX_INPUT]
    outputDir = os.path.join(extraArgList[IDX_OUTPUT], DATA_STR, entryCodeChar2and3, entryId)
    pdbConvention = extraArgList[IDX_PDB] #@UnusedVariable
    restraintsConvention = extraArgList[IDX_RESTRAINTS]
    archiveType = extraArgList[IDX_ARCHIVE] # Only used for deriving the input location not the output.
    projectType = extraArgList[IDX_PROJECT_TYPE]
    storeCING2db = stringMeansBooleanTrue( getDeepByKeysOrAttributes(extraArgList, IDX_STORE_DB))
    ranges = getDeepByKeysOrAttributes(extraArgList, IDX_RANGES)
    filterTopViolations = getDeepByKeysOrAttributes(extraArgList, IDX_FILTER_TOP)
    if filterTopViolations:
        filterTopViolations = int(filterTopViolations) # change '0' to 0
    filterVasco = getDeepByKeysOrAttributes(extraArgList, IDX_FILTER_VASCO)
    if filterVasco:
        filterVasco = int(filterVasco)
    else:
        filterVasco = 1 # Default should be True
    # end if
    singleCoreOperation = getDeepByKeysOrAttributes(extraArgList, IDX_SINGLE_CORE_OPERATION )
    if singleCoreOperation:
        singleCoreOperation = int(singleCoreOperation)
    else:
        singleCoreOperation = 0 # Default should be True
    # end if
    if archiveType == ARCHIVE_TYPE_FLAT:
        pass # default
    elif archiveType == ARCHIVE_TYPE_BY_ENTRY:
        inputDir = os.path.join(inputDir, entryId)
    elif archiveType == ARCHIVE_TYPE_BY_CH23:
        inputDir = os.path.join(inputDir, entryCodeChar2and3)
    elif archiveType == ARCHIVE_TYPE_BY_CH23_BY_ENTRY:
        inputDir = os.path.join(inputDir, entryCodeChar2and3, entryId)

    isRemoteOutputDir = False
    if '@' in outputDir:
        isRemoteOutputDir = True
    # end if
#    vc = vCing('.') # argument is a fake master_ssh_url not needed here.
    archive_id = getArchiveIdFromDirectoryName( outputDir )
    
    nTdebug("Using program arguments:")
    nTdebug("inputDir:             %s" % inputDir)
    nTdebug("outputDir:            %s" % outputDir)
    nTdebug("pdbConvention:        %s" % pdbConvention)
    nTdebug("restraintsConvention: %s" % restraintsConvention)
    nTdebug("archiveType:          %s" % archiveType)
    nTdebug("projectType:          %s" % projectType)
    nTdebug("storeCING2db:         %s" % storeCING2db)
    nTdebug("ranges:               %s" % ranges)
    nTdebug("filterTopViolations:  %s" % filterTopViolations)
    nTdebug("filterVasco:          %s" % filterVasco)
    nTdebug("singleCoreOperation:  %s" % singleCoreOperation)    
    nTdebug("")
    nTdebug("Using derived settings:")
    nTdebug("modelCount:           %s" % modelCount)
    nTdebug("isRemoteOutputDir:    %s" % isRemoteOutputDir)
    nTdebug("archive_id:            %s" % archive_id)
    
    
    # For NMR_REDO required as most efficient.
    if singleCoreOperation: 
        setToSingleCoreOperation()
    
    # presume the directory still needs to be created.
    cingEntryDir = entryId + ".cing"

    if os.path.isdir(cingEntryDir):
        if forceRedo:
            nTmessage("Enforcing a redo")
            rmtree(cingEntryDir)
        else:
            mainIndexFile = os.path.join(cingEntryDir, "index.html")
            isDone = os.path.isfile(mainIndexFile)
            if isDone:
                nTmessage("SKIPPING ENTRY ALREADY DONE")
                return
            nTmessage("REDOING BECAUSE VALIDATION CONSIDERED NOT DONE.")
            rmtree(cingEntryDir)
        # end if.
    # end if.

    if isRemoteOutputDir:
        os.chdir(cingDirTmp)
    else:
        os.chdir(outputDir)

    project = Project(entryId)
    if project.removeFromDisk():
        nTerror("Failed to remove existing project (if present)")
        return True
    # end if.

    formatFileName = '%s.tgz'
    if projectType == PROJECT_TYPE_CING:
        formatFileName = '%s.cing.tgz'
    elif projectType == PROJECT_TYPE_PDB:
        formatFileName = 'pdb%s.ent.gz'
    fileNameTgz = formatFileName % entryId

#    nTdebug("fileNameTgz: %s" % fileNameTgz)
    allowedInputProtocolList = 'http file ssh'.split()
    inputProtocal = string.split( inputDir, ':' )[0]
    if inputProtocal in allowedInputProtocolList:
        stillToRetrieve = False
        if os.path.exists(fileNameTgz):
            if forceRetrieveInput:
                os.unlink(fileNameTgz)
                stillToRetrieve = True
            # end if
        else:
            stillToRetrieve = True
        # end if
        if stillToRetrieve:
            retrieveTgzFromUrl(entryId, inputDir, archiveType=archiveType, formatFileName=formatFileName)
        # end if
        if not os.path.exists(fileNameTgz):
            nTerror("Tgz should already have been present skipping entry")
            return
        # end if
    else:
        nTdebug("Entry not retrieved which might be normal in some situations.")
    # end if.

    if projectType == PROJECT_TYPE_CING:
        # Needs to be copied because the open method doesn't take a directory argument..
#        fullFileNameTgz = os.path.join(inputDir, fileNameTgz)
#        shutil.copy(fullFileNameTgz, '.')
        project = Project.open(entryId, status='old')
        if not project:
            nTerror("Failed to init old project")
            return True
    elif projectType == PROJECT_TYPE_CCPN:
        project = Project.open(entryId, status='new')
        if not project.initCcpn(ccpnFolder=fileNameTgz, modelCount=modelCount):
            nTerror("Failed to init project from ccpn")
            return True
    elif projectType == PROJECT_TYPE_PDB:
        project = Project.open(entryId, status='new')
        pdbFilePath = entryId + ".pdb"
        gunzip(fileNameTgz, outputFileName=pdbFilePath, removeOriginal=True)
        project.initPDB(pdbFile=pdbFilePath, convention=IUPAC, nmodels=modelCount)
#        if tmpPdbFile:
        if True:
            nTdebug("Removing tmp: %s" % pdbFilePath)
            os.unlink(pdbFilePath)
    # end if
    if ranges is not None:
        project.molecule.setRanges(ranges)
    # end if
    if archive_id:
        project.molecule.setArchiveId(archive_id)
    # end if
    project.molecule.superpose(ranges=ranges)
    if filterTopViolations and not project.filterHighRestraintViol():
        nTerror("Failed to filterHighRestraintViol")    
####> MAIN UTILITY HERE
    if 0: # DEFAULT 0
        project.save()
    if project.validate(htmlOnly=htmlOnly, ranges=ranges, doProcheck=doProcheck, doWhatif=doWhatif,
            doWattos=doWattos, doQueeny = doQueeny, doTalos=doTalos, filterVasco = filterVasco ):
        nTerror("Failed to validate project read")
        return True
    # end if filterVasco
    
    # Write a single PDB file containing all models 
    # according to IUPAC conventions 
    project.export2PDB()
    
    project.save()

    if storeCING2db and archive_id:
        # Does require:
        #from cing.PluginCode.sqlAlchemy import csqlAlchemy
        # and should never crash  run.
#        archive_id = ARCHIVE_DEV_NRG_ID
#        if isProduction:
#            archive_id = ARCHIVE_NRG_ID
        try:
            if doStoreCING2db( entryId, archive_id, project=project):
                nTerror("Failed to store CING project's data to DB but continuing.")
        except:
            nTtracebackError()
            nTerror("Failed to store CING project's data due to above traceback error.")

    if projectType == PROJECT_TYPE_CCPN:
#        fileNameTgz = entryId + '.tgz'
        os.unlink(fileNameTgz) # temporary ccpn tgz
        if removeCcpnDirectory:
            rmdir(entryId) # ccpn dir may contain vasco info.

    if tgzCing:
        directoryNameCing = entryId + ".cing"
        tgzFileNameCing = directoryNameCing + ".tgz"
        if os.path.exists(tgzFileNameCing):
            nTwarning("Overwriting: " + tgzFileNameCing)
        cmd = "tar -czf %s %s" % (tgzFileNameCing, directoryNameCing)
        nTdebug("cmd: %s" % cmd)
#        do_cmd(cmd)
        status, result = commands.getstatusoutput(cmd)
        if status:
            nTerror("Failed to tar status: %s with result %s" % (status, result))
            return True
        if isRemoteOutputDir:
            if putFileBySsh(tgzFileNameCing, outputDir, ntriesMax = 2):
                nTerror("Failed to send File By Scp status: %s with result %s" % (status, result))
                nTerror("Maintaining results.")
                return True
            # end if
            nTmessage("Removing tgz result: %s" % tgzFileNameCing)
            os.remove(tgzFileNameCing)
            nTmessage("Removing cing dir itself: %s" % directoryNameCing)
            rmdir(directoryNameCing)
        else: # do NOT remove local copy
            pass
예제 #35
0
class AllChecks(TestCase):
    'Test case'
    cingDirTmpTest = os.path.join( cingDirTmp, 'test_classes2' )
    mkdirs( cingDirTmpTest )
    os.chdir(cingDirTmpTest)

    
    def __init__(self, *args, **kwds):
        TestCase.__init__(self, *args, **kwds)
        self.project = None
        self.r1 = None
        self.r2 = None
        self.r3 = None
        self.r4 = None
        self.r5 = None
        self.r6 = None
        self.r7 = None
        self.r8 = None
          
    def createSimpleFastProject(self):
        'create simple fast project'
        entryId = 'test'

        self.project = Project( entryId )
        self.project.removeFromDisk()
        self.project = Project.open( entryId, status='new' )


        mol = Molecule('test')
        self.project.appendMolecule(mol)
        c = mol.addChain('A')
        self.r1 = c.addResidue('VAL', 1, Nterminal = True)
        self.r2 = c.addResidue('VAL', 2)
        self.r3 = c.addResidue('GLU', 3)
        self.r4 = c.addResidue('TYR', 4)
        self.r5 = c.addResidue('PHE', 5)
        self.r6 = c.addResidue('GLY', 6)
        self.r7 = c.addResidue('ARG', 7)
        self.r8 = c.addResidue('LEU', 8, Cterminal = True)
        for r in mol.allResidues():
            r.addAllAtoms()
        mol.updateAll()
#        nTmessage( mol.format() )

    def test_simplifyForFcFeature(self):
        'test simplify Specifically For Fc Feature'
        self.createSimpleFastProject()
        _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep')
        atomPairs = NTlist()
        r1 = self.r1
        r2 = self.r2
#        r3 = self.r3
        atomPairs.append((r1.MG1, r2.MG1))
        atomPairs.append((r1.MG2, r2.MG1))
        atomPairs.append((r1.MG1, r2.MG2))
        atomPairs.append((r1.MG2, r2.MG2))

#        atomPairs.append((r2.HN, r2.MG1))
#        atomPairs.append((r2.HN, r2.MG2))
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
        if distanceRestraint.isValid:
            _distanceRestraintList.append(distanceRestraint)
        else:
            nTerror('Failed to initialize DR with %s' % atomPairs)
#        nTdebug("dr before: %s" % formatall(distanceRestraint))

        # Takes 4 simplification iterations.
        self.assertEqual(distanceRestraint.simplifyForFc(), DistanceRestraint.STATUS_SIMPLIFIED)
#        nTdebug("dr after 1: %s" % formatall(distanceRestraint))
        self.assertEqual(distanceRestraint.simplifyForFc(), DistanceRestraint.STATUS_SIMPLIFIED)
#        nTdebug("dr after 2: %s" % formatall(distanceRestraint))
        self.assertEqual(distanceRestraint.simplifyForFc(), DistanceRestraint.STATUS_SIMPLIFIED)
#        nTdebug("dr after 3: %s" % formatall(distanceRestraint))
        self.assertEqual(distanceRestraint.simplifyForFc(), DistanceRestraint.STATUS_NOT_SIMPLIFIED)
#        nTdebug("dr after 4: %s" % formatall(distanceRestraint)) # don't print as it contains error token.
        _x = "dr after 4: %s" % formatall(distanceRestraint)

    def test_simplifyForFcFeature_2(self):
        'test simplify Specifically For Fc Feature 2'        
        # disfunctional as of yet
        self.createSimpleFastProject()
        _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep')
        atomPairs = NTlist()
#        r1 = self.r1
        r2 = self.r2
#        r3 = self.r3
        atomPairs.append((r2.HN, r2.MG1))
        atomPairs.append((r2.MG2, r2.HN))

#        atomPairs.append((r2.HN, r2.MG1))
#        atomPairs.append((r2.HN, r2.MG2))
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
        _distanceRestraintList.append(distanceRestraint)
#        nTdebug("dr before: %s" % formatall(distanceRestraint))

        self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_SIMPLIFIED)
#        nTdebug("dr after 1: %s" % formatall(distanceRestraint))


    def test_CombinationToPseudo(self):
        ' test combination to Pseudo'
        self.createSimpleFastProject()

        r1 = self.r1
        r2 = self.r2
        r3 = self.r3
        atomLoL = [[r2.HN],
                          [r3.HB2, r3.HB3],
                          [r3.HB2],
                          [r1.HG11, r1.HG12, r1.HG13],
                          [r1.HG12, r1.HG11, r1.HG13],
                          [r1.HG11, r1.HG12, r1.HG13, r1.HG21, r1.HG22, r1.HG23], # unrepresented by below method.
                          ]
        pseudoListResultExpected = [ None,
                                    r3.QB,
                                    None,
                                    r1.MG1, # TODO: update these to MD1 when CING has IUPAC internally.
                                    r1.MG1,
                                    None,
                                     ]

        i = -1
        for atomList in atomLoL:
            i += 1
            firstAtom = atomList[0]
            self.assertEqual( firstAtom.getRepresentativePseudoAtom(atomList), pseudoListResultExpected[i])

    def test_CombinationToPseudoDouble(self):
        ' test combination to Pseudo Double'
#        'Simulate 1a24 1254.00     A    3    TYR    QD    A    8    GLN    QG'
        self.createSimpleFastProject()

        e = self.r3 # GLN
        y = self.r4 # TYR
        _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep')
        atomPairs = NTlist((e.HG2, y.HB2),
                           (e.HG3, y.HB2),
                           (e.HG2, y.HB3),
                           (e.HG3, y.HB3))
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
#        nTdebug("before: %r" % distanceRestraint  )
        self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_SIMPLIFIED)
#        nTdebug("after: %r" % distanceRestraint  )

    def test_CombiToPseudoDouble_2(self):
        'test_CombiToPseudoDouble_2'
#        'Simulate 1a24 1254.00     A    3    TYR    QD    A    8    GLN    QB'
        self.createSimpleFastProject()

#        e = self.r3 # GLN
        y = self.r4 # TYR
        _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep')
        atomPairs = NTlist((y.HE1, y.HB2),
                           (y.HE2, y.HB2),
                           (y.HE1, y.HB3),
                           (y.HE2, y.HB3))
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
#        nTdebug("before: %r" % distanceRestraint  )
        self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_SIMPLIFIED)
#        nTdebug("after: %r" % distanceRestraint  )

    def test_CombiToPseudoQuadruple(self):
        ' test combination to Pseudo 4 some.'        
#        'Simulate 1a24 1254.00     A    3    TYR    QR    A    8    GLN    QB'
        self.createSimpleFastProject()

        y = self.r5 # PHE
        _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep')
        atomPairs = NTlist((y.QE, y.H),
                           (y.QD, y.H)
                           )
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
#        nTdebug("before: %r" % distanceRestraint  )
        self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_NOT_SIMPLIFIED)
#        nTdebug("after: %r" % distanceRestraint  )

    def test_Simplify(self):
        'test Simplify'
        self.createSimpleFastProject()

        y = self.r5 # PHE
        _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep')
        atomPairs = NTlist((y.QE, y.H),
                           (y.QE, y.H)
                           )
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
#        nTdebug("before: %r" % distanceRestraint  )
        self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_NOT_SIMPLIFIED)
#        nTdebug("after: %r" % distanceRestraint  )

    def test_Simplify2(self):
        'test Simplify2'
        _help = """
        For 1a24
        783.00    A    20    PRO    QB    A    23    LEU    MD1   3.20    7.90    2.96    0.56    2.56    3.35    0.32    0.45    0.64    0    0    0
        783.01    A    20    PRO    QB    A    23    LEU    QD    3.20    7.90    2.96    0.56    2.56    3.35    0.32    0.45    0.64    0    0    0
        """
        self.createSimpleFastProject()

        y = self.r5 # PHE
        _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep')
        atomPairs = NTlist((y.QE, y.H),
                           (y.QE, y.H)
                           )
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
#        nTdebug("before: %r" % distanceRestraint  )
        self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_NOT_SIMPLIFIED)
#        nTdebug("after: %r" % distanceRestraint  )

    def test_Simplify3(self):
        'test simplify 3'
        _help = """
        For 1a24
        783.00    A    20    PRO    QB    A    23    LEU    MD1   3.20    7.90    2.96    0.56    2.56    3.35    0.32    0.45    0.64    0    0    0
        783.01    A    20    PRO    QB    A    23    LEU    QD    3.20    7.90    2.96    0.56    2.56    3.35    0.32    0.45    0.64    0    0    0
        """
        self.createSimpleFastProject()

        y = self.r8 # LEU
        _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep')
        atomPairs = NTlist((y.QD,  y.H),
                           (y.MD1, y.H)
                           )
        distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0)
#        nTdebug("before: %r" % distanceRestraint  )
        self.assertEqual(distanceRestraint.removeDuplicateAtomPairs2(), DistanceRestraint.STATUS_REMOVED_DUPLICATE)
예제 #36
0
    def test_RangeSelection(self):
        cing.verbosity = verbosityDebug
        entryId = 'testEntry'
        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')
        mol = Molecule('testMol')
        project.appendMolecule(mol)
        offset1 = -10
        # h**o dimer
        chainList = ('A', 'B')
        sequence = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
        seqL = len(sequence)
        lastResidueI = seqL - 1
        for cId in chainList:
            c = mol.addChain(cId)
            for i, rName in enumerate(sequence):
                rNumber = i + offset1
                Nterminal = False  # pylint: disable=C0103
                Cterminal = False  # pylint: disable=C0103
                if i == 0:
                    Nterminal = True  # pylint: disable=C0103
                if i == lastResidueI:
                    Cterminal = True  # pylint: disable=C0103
                r = c.addResidue(rName,
                                 rNumber,
                                 Nterminal=Nterminal,
                                 Cterminal=Cterminal)
                if r:
                    #                    nTdebug("Adding atoms to residue: %s" % r)
                    r.addAllAtoms()
                    for atom in r.allAtoms():
                        atom.addCoordinate(0.0, 1.0, 2.0, 40.0)
#                else:
#                    nTdebug("Skipping atoms for residue: %s" % r)
# end if
# end for
# end for chain

# another h**o dimer with renumbering.
        chainList = ('C', 'D')
        offset2 = 100
        for cId in chainList:
            c = mol.addChain(cId)
            for i, rName in enumerate(sequence):
                rNumber = i + offset2
                Nterminal = False  # pylint: disable=C0103
                Cterminal = False  # pylint: disable=C0103
                if i == 0:
                    Nterminal = True  # pylint: disable=C0103
                if i == lastResidueI:
                    Cterminal = True  # pylint: disable=C0103
                r = c.addResidue(rName,
                                 rNumber,
                                 Nterminal=Nterminal,
                                 Cterminal=Cterminal)
                if r:
                    #                    nTdebug("Adding atoms to residue: %s" % r)
                    r.addAllAtoms()


#                else:
#                    nTdebug("Skipping atoms for residue: %s" % r)
# end if
# end for
# end for chain
        nTdebug("Done creating simple fake molecule")
        self.assertFalse(mol.updateAll())
        nTmessage(mol.format())

        # Nada
        selectedResidueList = mol.ranges2list('')
        self.assertEquals(len(selectedResidueList), 2 * len(chainList) * seqL)

        # Single residue
        selectedResidueList = mol.ranges2list('A.' + str(offset1))
        self.assertEquals(len(selectedResidueList), 1)
        nTdebug("Selected residues: %s" % str(selectedResidueList))

        # Two residues
        selectedResidueList = mol.ranges2list(str(offset1))
        self.assertEquals(len(selectedResidueList), 2)
        nTdebug("Selected residues: %s" % str(selectedResidueList))

        # Four residues in ranges
        selectedResidueList = mol.ranges2list('1-2')
        self.assertEquals(len(selectedResidueList), 4)
        nTdebug("Selected residues: %s" % str(selectedResidueList))

        # Eight residues in negative crossing ranges
        selectedResidueList = mol.ranges2list('-1-2')
        self.assertEquals(len(selectedResidueList), 8)
        nTdebug("Selected residues: %s" % str(selectedResidueList))

        selectedResidueList = mol.ranges2list('A.-5--2')
        self.assertEquals(len(selectedResidueList), 4)
        nTdebug("Selected residues: %s" % str(selectedResidueList))

        selectedResidueList = mol.ranges2list('-999-999')
        nTdebug("Selected residues: %s" % str(selectedResidueList))
        self.assertEquals(len(selectedResidueList), 2 * len(chainList) * seqL)

        residueList2StartStopList = mol.ranges2StartStopList('-999-999')
        nTdebug('residueList2StartStopList: %s' %
                str(residueList2StartStopList))
        self.assertEquals(len(residueList2StartStopList), 8)

        #        """
        #        Possible 5 situations:
        #        a      # 1 # positive int
        #        -a     # 2 # single int
        #        -a-b   # 3 #
        #        -a--b  # 4 #
        #        a-b    # 5 # most common
        #        """
        inputList = """
                      A.1
                      A.1-3
                      A.-2--1
                      A.-2-1
                      A.-3
                    """.split()
        for i, ranges in enumerate(inputList):
            nTdebug("test_RangeSelection: %d %s" % (i, ranges))
            residueList = mol.setResiduesFromRanges(ranges)
            #            nTdebug('residueList: [%s]' % residueList)
            rangesRecycled = mol.residueList2Ranges(residueList)
            #            nTdebug('rangesRecycled: [%s]' % rangesRecycled)
            self.assertEquals(ranges, rangesRecycled)

        res1, res2 = mol.ranges2list('A.1,A.3')
        self.assertEquals(2, residueNumberDifference(res1, res2))
        res3, res4 = mol.ranges2list('A.5,A.8')
        self.assertEquals(3, residueNumberDifference(res3, res4))
        res5, res6 = mol.ranges2list('B.9,B.10')
        self.assertEquals(1, residueNumberDifference(res5, res6))

        ranges = mol.startStopList2ranges([res1, res2])
        self.assertEquals('A.1-3', ranges)
        ranges = mol.startStopList2ranges([res1, res2, res3, res4])
        self.assertEquals('A.1-3,A.5-8', ranges)
        ranges = mol.startStopList2ranges([res1, res2, res5, res6])
        self.assertEquals('A.1-3,B.9-10', ranges)

        # Check other routine
        chain0 = mol.allChains()[0]
        chain1 = mol.allChains()[1]
        atomList = chain0.getRepresentingAtomListsPerResidue(chain1)
        nTdebug("atomList: %s" % str(atomList))
        self.assertEquals(len(atomList[0]), 5)
예제 #37
0
    def test_GetMolTypeCountList(self):
        cing.verbosity = verbosityDebug
        entryId = 'test'
        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')

        mol = Molecule('test')
        project.appendMolecule(mol)
        c = mol.addChain('A')
        c.addResidue('ALA', 1, Nterminal=True)
        c.addResidue('VAL', 2)
        c.addResidue('PHE', 3)
        c.addResidue('ARG', 4)
        c.addResidue('GLU', 5, Cterminal=True)
        c = mol.addChain('B')
        c.addResidue('DG', 1, Nterminal=True)
        c.addResidue('DA', 2)
        c.addResidue('DT', 3)
        c.addResidue('DC', 4, Cterminal=True)
        c = mol.addChain('C')

        c.addResidue('RGUA', 1, convention=INTERNAL_0, Nterminal=True)
        c.addResidue(
            'RADE',
            2,
            convention=INTERNAL_0,
        )
        c.addResidue(
            'URA',
            3,
            convention=INTERNAL_0,
        )  # not RTHY normally of course.
        c.addResidue(
            'RTHY',
            4,
            convention=INTERNAL_0,
        )
        c.addResidue('RCYT', 5, convention=INTERNAL_0, Cterminal=True)
        c = mol.addChain('D')
        for i in range(1, 11):
            c.addResidue('HOH', i)
        # end for
        c = mol.addChain('E')  # Unknown residue to CING
        c.addResidue('ACE', 1)
        c = mol.addChain('F')  # Ions are also other
        c.addResidue('CA2P', 1)
        for residue in mol.allResidues():
            residue.addAllAtoms()
        # end for
        mol.updateAll()
        nTmessage(mol.format())
        for c in mol.allChains():
            nTmessage(c.format())
            nTmessage("idxMolType: %s" % (c.getIdxMolType()))
        # end for

        nTmessage("Count the molecule types")
        molTypeCountList = mol.getMolTypeCountList()
        p_protein_count = molTypeCountList[mapMoltypeToInt[PROTEIN_STR]]
        p_dna_count = molTypeCountList[mapMoltypeToInt[DNA_STR]]
        p_rna_count = molTypeCountList[mapMoltypeToInt[RNA_STR]]
        p_water_count = molTypeCountList[mapMoltypeToInt[WATER_STR]]
        p_other_count = molTypeCountList[mapMoltypeToInt[OTHER_STR]]
        self.assertEqual(1, p_protein_count)
        self.assertEqual(1, p_dna_count)
        self.assertEqual(1, p_rna_count)
        self.assertEqual(1, p_water_count)
        self.assertEqual(2, p_other_count)

        nTmessage("Count the residue types")
        molTypeResidueCountList = mol.getMolTypeResidueCountList()
        p_res_protein_count = molTypeResidueCountList[
            mapMoltypeToInt[PROTEIN_STR]]
        p_res_dna_count = molTypeResidueCountList[mapMoltypeToInt[DNA_STR]]
        p_res_rna_count = molTypeResidueCountList[mapMoltypeToInt[RNA_STR]]
        p_res_water_count = molTypeResidueCountList[mapMoltypeToInt[WATER_STR]]
        p_res_other_count = molTypeResidueCountList[mapMoltypeToInt[OTHER_STR]]
        self.assertEqual(5, p_res_protein_count)
        self.assertEqual(4, p_res_dna_count)
        self.assertEqual(5, p_res_rna_count)
        self.assertEqual(10, p_res_water_count)
        self.assertEqual(2, p_res_other_count)

        nTmessage("Select a list of residues.")
        inputResList = (('A', 5), ('B', 2), ('A', 6), ('X', 1)
                        )  # The last 2 are non-existing residues
        # should give two warnings for a non-existing residue
        resList = project.decodeResidueList(inputResList)
        self.assertEqual(2, len(resList))
예제 #38
0
    def test_RangeSelection(self):
        cing.verbosity = verbosityDebug
        entryId = 'testEntry'
        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')
        mol = Molecule('testMol')
        project.appendMolecule(mol)
        offset1 = -10
        # h**o dimer
        chainList = ( 'A', 'B' )
        sequence = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
        seqL = len(sequence)
        lastResidueI = seqL - 1
        for cId in chainList:
            c = mol.addChain(cId)
            for i, rName in enumerate(sequence):
                rNumber = i+offset1
                Nterminal = False # pylint: disable=C0103
                Cterminal = False # pylint: disable=C0103
                if i == 0:
                    Nterminal = True # pylint: disable=C0103
                if i == lastResidueI:
                    Cterminal = True # pylint: disable=C0103
                r = c.addResidue(rName, rNumber, Nterminal = Nterminal, Cterminal = Cterminal)
                if r:
#                    nTdebug("Adding atoms to residue: %s" % r)
                    r.addAllAtoms()
                    for atom in r.allAtoms():
                        atom.addCoordinate(0.0, 1.0, 2.0, 40.0)
#                else:
#                    nTdebug("Skipping atoms for residue: %s" % r)
                # end if
            # end for
        # end for chain

        # another h**o dimer with renumbering.
        chainList = ( 'C', 'D' )
        offset2 = 100
        for cId in chainList:
            c = mol.addChain(cId)
            for i, rName in enumerate(sequence):
                rNumber = i+offset2
                Nterminal = False # pylint: disable=C0103
                Cterminal = False # pylint: disable=C0103
                if i == 0:
                    Nterminal = True # pylint: disable=C0103
                if i == lastResidueI:
                    Cterminal = True # pylint: disable=C0103
                r = c.addResidue(rName, rNumber, Nterminal = Nterminal, Cterminal = Cterminal)
                if r:
#                    nTdebug("Adding atoms to residue: %s" % r)
                    r.addAllAtoms()
#                else:
#                    nTdebug("Skipping atoms for residue: %s" % r)
                # end if
            # end for
        # end for chain
        nTdebug("Done creating simple fake molecule")
        self.assertFalse( mol.updateAll() )
        nTmessage( mol.format() )

        # Nada
        selectedResidueList = mol.ranges2list('')
        self.assertEquals( len(selectedResidueList), 2*len(chainList)*seqL)

        # Single residue
        selectedResidueList = mol.ranges2list('A.'+str(offset1))
        self.assertEquals( len(selectedResidueList), 1)
        nTdebug("Selected residues: %s" % str(selectedResidueList))

        # Two residues
        selectedResidueList = mol.ranges2list(str(offset1))
        self.assertEquals( len(selectedResidueList), 2)
        nTdebug("Selected residues: %s" % str(selectedResidueList))

        # Four residues in ranges
        selectedResidueList = mol.ranges2list('1-2')
        self.assertEquals( len(selectedResidueList), 4)
        nTdebug("Selected residues: %s" % str(selectedResidueList))

        # Eight residues in negative crossing ranges
        selectedResidueList = mol.ranges2list('-1-2')
        self.assertEquals( len(selectedResidueList), 8)
        nTdebug("Selected residues: %s" % str(selectedResidueList))


        selectedResidueList = mol.ranges2list('A.-5--2')
        self.assertEquals( len(selectedResidueList), 4)
        nTdebug("Selected residues: %s" % str(selectedResidueList))

        selectedResidueList = mol.ranges2list('-999-999')
        nTdebug("Selected residues: %s" % str(selectedResidueList))
        self.assertEquals( len(selectedResidueList), 2*len(chainList)*seqL)

        residueList2StartStopList = mol.ranges2StartStopList('-999-999')
        nTdebug('residueList2StartStopList: %s' % str(residueList2StartStopList))
        self.assertEquals( len(residueList2StartStopList), 8 )

#        """
#        Possible 5 situations:
#        a      # 1 # positive int
#        -a     # 2 # single int
#        -a-b   # 3 #
#        -a--b  # 4 #
#        a-b    # 5 # most common
#        """
        inputList = """
                      A.1
                      A.1-3
                      A.-2--1
                      A.-2-1
                      A.-3
                    """.split()
        for i, ranges in enumerate(inputList):
            nTdebug("test_RangeSelection: %d %s" % (i, ranges))
            residueList = mol.setResiduesFromRanges(ranges)
#            nTdebug('residueList: [%s]' % residueList)
            rangesRecycled = mol.residueList2Ranges(residueList)
#            nTdebug('rangesRecycled: [%s]' % rangesRecycled)
            self.assertEquals( ranges, rangesRecycled )

        res1, res2 = mol.ranges2list('A.1,A.3')
        self.assertEquals( 2, residueNumberDifference(res1, res2))
        res3, res4 = mol.ranges2list('A.5,A.8')
        self.assertEquals( 3, residueNumberDifference(res3, res4))
        res5, res6 = mol.ranges2list('B.9,B.10')
        self.assertEquals( 1, residueNumberDifference(res5, res6))

        ranges = mol.startStopList2ranges([res1, res2])
        self.assertEquals( 'A.1-3', ranges)
        ranges = mol.startStopList2ranges([res1, res2, res3, res4])
        self.assertEquals( 'A.1-3,A.5-8', ranges)
        ranges = mol.startStopList2ranges([res1, res2, res5, res6])
        self.assertEquals( 'A.1-3,B.9-10', ranges)

        # Check other routine
        chain0 = mol.allChains()[0]
        chain1 = mol.allChains()[1]
        atomList = chain0.getRepresentingAtomListsPerResidue(chain1)
        nTdebug("atomList: %s" % str(atomList))
        self.assertEquals( len(atomList[0]), 5)
예제 #39
0
    def test_GetMolTypeCountList(self):
        cing.verbosity = verbosityDebug
        entryId = 'test'
        project = Project(entryId)
        self.failIf(project.removeFromDisk())
        project = Project.open(entryId, status='new')

        mol = Molecule('test')
        project.appendMolecule(mol)
        c = mol.addChain('A')
        c.addResidue('ALA', 1, Nterminal = True)
        c.addResidue('VAL', 2)
        c.addResidue('PHE', 3)
        c.addResidue('ARG', 4)
        c.addResidue('GLU', 5, Cterminal = True)
        c = mol.addChain('B')
        c.addResidue('DG', 1, Nterminal = True)
        c.addResidue('DA', 2)
        c.addResidue('DT', 3)
        c.addResidue('DC', 4, Cterminal = True)
        c = mol.addChain('C')

        c.addResidue('RGUA', 1, convention=INTERNAL_0, Nterminal = True)
        c.addResidue('RADE', 2, convention=INTERNAL_0, )
        c.addResidue('URA', 3, convention=INTERNAL_0, ) # not RTHY normally of course.
        c.addResidue('RTHY', 4, convention=INTERNAL_0, )
        c.addResidue('RCYT',  5, convention=INTERNAL_0, Cterminal = True)
        c = mol.addChain('D')
        for i in range(1,11):
            c.addResidue('HOH', i )
        # end for
        c = mol.addChain('E') # Unknown residue to CING
        c.addResidue('ACE', 1 )
        c = mol.addChain('F') # Ions are also other
        c.addResidue('CA2P', 1 )
        for residue in mol.allResidues():
            residue.addAllAtoms()
        # end for
        mol.updateAll()
        nTmessage( mol.format() )
        for c in mol.allChains():
            nTmessage( c.format() )
            nTmessage( "idxMolType: %s" % (c.getIdxMolType()))
        # end for

        nTmessage("Count the molecule types")
        molTypeCountList = mol.getMolTypeCountList()
        p_protein_count = molTypeCountList[ mapMoltypeToInt[PROTEIN_STR] ]
        p_dna_count     = molTypeCountList[ mapMoltypeToInt[DNA_STR] ]
        p_rna_count     = molTypeCountList[ mapMoltypeToInt[RNA_STR] ]
        p_water_count   = molTypeCountList[ mapMoltypeToInt[WATER_STR] ]
        p_other_count   = molTypeCountList[ mapMoltypeToInt[OTHER_STR] ]
        self.assertEqual(1, p_protein_count)
        self.assertEqual(1, p_dna_count  )
        self.assertEqual(1, p_rna_count  )
        self.assertEqual(1, p_water_count)
        self.assertEqual(2, p_other_count)

        nTmessage("Count the residue types")
        molTypeResidueCountList = mol.getMolTypeResidueCountList()
        p_res_protein_count = molTypeResidueCountList[ mapMoltypeToInt[PROTEIN_STR] ]
        p_res_dna_count     = molTypeResidueCountList[ mapMoltypeToInt[DNA_STR] ]
        p_res_rna_count     = molTypeResidueCountList[ mapMoltypeToInt[RNA_STR] ]
        p_res_water_count   = molTypeResidueCountList[ mapMoltypeToInt[WATER_STR] ]
        p_res_other_count   = molTypeResidueCountList[ mapMoltypeToInt[OTHER_STR] ]
        self.assertEqual(5, p_res_protein_count)
        self.assertEqual(4, p_res_dna_count  )
        self.assertEqual(5, p_res_rna_count  )
        self.assertEqual(10, p_res_water_count)
        self.assertEqual(2, p_res_other_count)

        nTmessage("Select a list of residues.")
        inputResList = (('A', 5),('B', 2),('A', 6),('X', 1)) # The last 2 are non-existing residues
        # should give two warnings for a non-existing residue
        resList = project.decodeResidueList( inputResList )
        self.assertEqual(2, len(resList) )
예제 #40
0
파일: d1d2plot.py 프로젝트: VuisterLab/cing
def plotDihedralD1D2():
    dihedralName1 = 'Cb4N'
    dihedralName2 = 'Cb4C'
    graphicsFormat = "png"


    entryId = "1brv" # Small much studied PDB NMR entry
#        entryId = "1hy8" # small, single model, very low scoring entry

    pdbDirectory = os.path.join(cingDirTestsData, "pdb", entryId)
    pdbFileName = "pdb" + entryId + ".ent"
    pdbFilePath = os.path.join(pdbDirectory, pdbFileName)

    # does it matter to import it just now?
    project = Project(entryId)
    project.removeFromDisk()
    project = Project.open(entryId, status='new')
    project.initPDB(pdbFile=pdbFilePath, convention=IUPAC)

#        ssType = 'E'
#        resType = 'GLY'
#        for ssType in histRamaBySsAndResType.keys():
#            ssTypeForFileName = ssType.replace(' ', '_')
    titleStr = 'd1d2 all resType'
    nTmessage("plotting: %s" % titleStr)
#            hist = histd1d2BySsAndResType[ssType][resType]

    ps = NTplotSet() # closes any previous plots
    ps.hardcopySize = (500, 500)

#                residueName = resType + ""
    x = NTlist(-45, -80, 125) # outside the range.
    y = NTlist(-65, -63, -125)

    # important to switch to temp space before starting to generate files for the project.
#        project     = Project('testPlotHistoDihedrald1d2')
    plotparams1 = project.plotParameters.getdefault(dihedralName1, 'dihedralDefault')
    plotparams2 = project.plotParameters.getdefault(dihedralName2, 'dihedralDefault')

    x.limit(plotparams1.min, plotparams1.max)
    y.limit(plotparams2.min, plotparams2.max)

    plot = NTplot(title=titleStr,
      xRange=(plotparams1.min, plotparams1.max),
      xTicks=range(int(plotparams1.min), int(plotparams1.max + 1), plotparams1.ticksize),
      xLabel=dihedralName1,
      yRange=(plotparams2.min, plotparams2.max),
      yTicks=range(int(plotparams2.min), int(plotparams2.max + 1), plotparams2.ticksize),
      yLabel=dihedralName2)
    ps.addPlot(plot)

    # Plot a density background
    histList = []
    ssTypeList = hPlot.histd1BySs0.keys() # TODO: check this histd1BySs0 attribute. UNTESTED.
    ssTypeList.sort() # in place sort to: space, H, S
    for ssType in ssTypeList:
        hist = getDeepByKeys(hPlot.histd1BySs0, ssType)
        if hist != None:
            nTdebug('appending [%s]' % ssType)
            histList.append(hist)
    if histList:
        plot.dihedralComboPlot(histList)
#            fn = os.path.join('bySsAndResType', ( ssTypeForFileName+"_"+resType+"."+graphicsFormat))
#            fn = os.path.join('byResType', ( resType+"."+graphicsFormat))


    fpGood = open(project.name + '.testCb2Good.out', 'w')
    fpBad = open(project.name + '.testCb2Bad.out', 'w')

    mCount = project.molecule.modelCount

    for res in project.molecule.A.allResidues():
        triplet = NTlist()
        for i in [-1, 0, 1]:
            triplet.append(res.sibling(i))
        if None in triplet:
            nTdebug('Skipping ' % res)

        else:
            ca_atms = triplet.zap('CA')
            cb_atms = triplet.zap('CB')

            nTdebug("%s %s %s %s" % (res, triplet, ca_atms, cb_atms))

            if None in cb_atms: # skip Gly for now
                nTdebug('Skipping %s' % res)
            else:
                d1 = Dihedral(res, 'Cb4N', range=[0.0, 360.0])
                d1.atoms = [cb_atms[0], ca_atms[0], ca_atms[1], cb_atms[1]]
                d1.calculateValues()
                res['Cb4N'] = d1 # append dihedral to residue

                d2 = Dihedral(res, 'Cb4C', range=[0.0, 360.0])
                d2.atoms = [cb_atms[1], ca_atms[1], ca_atms[2], cb_atms[2]]
                d2.calculateValues()
                res['Cb4C'] = d2 # append dihedral to residue

                bb = getDeepByKeys(res, WHATIF_STR, BBCCHK_STR, VALUE_LIST_STR, 0) # check first one.
                if bb == None:
                    nTdebug('Skipping without BB %s' % res)
                    continue

                if d1.cv < 0.03 and d2.cv < 0.03: # Only include structured residues
                    for i in range(mCount): # Consider each model individually
    #                    bb = res.Whatif.bbNormality.valueList[i]
                        bb = getDeepByKeys(res, WHATIF_STR, BBCCHK_STR, VALUE_LIST_STR, i)
                        if bb == None:
                            nTdebug('Skipping without BB %s' % res)
                            continue
                        angles = NTlist() # store phi, psi, chi1, chi2
                        for angle in ['PHI', 'PSI', 'CHI1', 'CHI2']:
                            if res.has_key(angle):
                                angles.append(res[angle][i])
                            else:
                                angles.append(0.0)
                        #end for
                        if bb < 20.0: # Arbitrary 20 bb occurences as cuttoff for now
                            fprintf(fpBad,  '%4d   %7.2f  %7.2f  %7.2f  %s  %s %s\n', 
                                    res.resNum, d1[i], d2[i], bb, angles.format("%7.2f  "), res, res.dssp.consensus)
                        else:
                            fprintf(fpGood, '%4d   %7.2f  %7.2f  %7.2f  %s  %s %s\n', 
                                    res.resNum, d1[i], d2[i], bb, angles.format("%7.2f  "), res, res.dssp.consensus)
                #end if
            #end if
        #end if
    #end for
    fpBad.close()
    fpGood.close()

    fn = "allRestype_d1d2." + graphicsFormat
    ps.hardcopy(fn, graphicsFormat)
예제 #41
0
def main(entryId, *extraArgList):
    """inputDir may be a directory or a url. A url needs to start with http://.
    """

    fastestTest = True # default: False
#    ranges=AUTO_STR # default is None retrieved from DBMS csv files.
    htmlOnly = False # default: False but enable it for faster runs without some actual data.
    doWhatif = True # disables whatif actual run
    doProcheck = True
    doWattos = True
    doTalos = True
    tgzCing = True # default: True # Create a tgz for the cing project. In case of a CING project input it will be overwritten.
    modelCount = None # default setting is None
    if fastestTest:
        modelCount = 3
        htmlOnly = True
        doWhatif = False
        doProcheck = False
        doWattos = False
        doTalos = False
    force_redo = True
    force_retrieve_input = True


    nTmessage(cing.cingDefinitions.getHeaderString())
    nTmessage(cing.systemDefinitions.getStartMessage())

    expectedArgumentList = [ 'inputDir', 'outputDir', 'pdbConvention', 'restraintsConvention', 'archiveType','projectType','storeCING2db']
    expectedNumberOfArguments = len(expectedArgumentList)
    if len(extraArgList) != expectedNumberOfArguments:
        nTerror("Got arguments: " + repr(extraArgList))
        nTerror("Failed to get expected number of arguments: %d got %d" % (
            expectedNumberOfArguments, len(extraArgList)))
        nTerror("Expected arguments: %s" % expectedArgumentList)
        return True

    entryCodeChar2and3 = entryId[1:3]

    inputDir = extraArgList[0]
    outputDir = os.path.join(extraArgList[1], DATA_STR, entryCodeChar2and3, entryId)
    pdbConvention = extraArgList[2] #@UnusedVariable
    restraintsConvention = extraArgList[3]
    archiveType = extraArgList[4]
    projectType = extraArgList[5]
    storeCING2db = False
    if len(extraArgList) >= expectedNumberOfArguments:
        storeCING2db = extraArgList[6]

    if archiveType == ARCHIVE_TYPE_FLAT:
        pass
        # default
    elif archiveType == ARCHIVE_TYPE_BY_ENTRY:
        inputDir = os.path.join(inputDir, entryId)
    elif archiveType == ARCHIVE_TYPE_BY_CH23:
        inputDir = os.path.join(inputDir, entryCodeChar2and3)
    elif archiveType == ARCHIVE_TYPE_BY_CH23_BY_ENTRY:
        inputDir = os.path.join(inputDir, entryCodeChar2and3, entryId)

    ranges = None
#    targetId = getTargetForFullEntryName(entryId)
#    if not targetId:
#        nTerror("Failed to getTargetForFullEntryName for entryId: %s" % entryId)
#        return True
#    ranges = getRangesForTarget(targetId)
#    if ranges == None:
#        nTerror("Failed to getRangesForTarget for targetId: %s" % targetId)
#        return True


    nTdebug("Using:")
    nTdebug("inputDir:             %s" % inputDir)
    nTdebug("outputDir:            %s" % outputDir)
    nTdebug("pdbConvention:        %s" % pdbConvention)
    nTdebug("restraintsConvention: %s" % restraintsConvention)
    nTdebug("archiveType:          %s" % archiveType)
    nTdebug("projectType:          %s" % projectType)
    nTdebug("modelCount:           %s" % modelCount)
    nTdebug("storeCING2db:         %s" % storeCING2db)
    nTdebug("ranges:               %s" % ranges)
    # presume the directory still needs to be created.
    cingEntryDir = entryId + ".cing"

    if os.path.isdir(cingEntryDir):
        if force_redo:
            nTmessage("Enforcing a redo")
            rmtree(cingEntryDir)
        else:
            mainIndexFile = os.path.join(cingEntryDir, "index.html")
            isDone = os.path.isfile(mainIndexFile)
            if isDone:
                nTmessage("SKIPPING ENTRY ALREADY DONE")
                return
            nTmessage("REDOING BECAUSE VALIDATION CONSIDERED NOT DONE.")
            rmtree(cingEntryDir)
        # end if.
    # end if.

    os.chdir(outputDir)

    project = Project(entryId)
    if project.removeFromDisk():
        nTerror("Failed to remove existing project (if present)")
        return True
    # end if.

#    extension = '.tgz'
    formatFileName = '%s.tgz'
#    fileNameTgz = entryId + '.tgz'
    if projectType == PROJECT_TYPE_CING:
#        fileNameTgz = entryId + '.cing.tgz'
        formatFileName = '%s.cing.tgz'
    elif projectType == PROJECT_TYPE_PDB:
        formatFileName = 'pdb%s.ent.gz'
    fileNameTgz = formatFileName % entryId

#    nTdebug("fileNameTgz: %s" % fileNameTgz)
    # if true will do retrieveTgzFromUrl.
    if inputDir.startswith("http") or inputDir.startswith("file"):
        stillToRetrieve = False
        if os.path.exists(fileNameTgz):
            if force_retrieve_input:
                os.unlink(fileNameTgz)
                stillToRetrieve = True
            # end if
        else:
            stillToRetrieve = True
        # end if
        if stillToRetrieve:
            retrieveTgzFromUrl(entryId, inputDir, archiveType=archiveType, formatFileName=formatFileName)
        # end if
        if not os.path.exists(fileNameTgz):
            nTerror("Tgz should already have been present skipping entry")
            return
        # end if
    # end if.
#            retrieveTgzFromUrl(entryId, inputDir)

    if projectType == PROJECT_TYPE_CING:
        # Needs to be copied because the open method doesn't take a directory argument..
        fullFileNameTgz = os.path.join(inputDir, fileNameTgz)
        shutil.copy(fullFileNameTgz, '.')
        project = Project.open(entryId, status='old')
        if not project:
            nTerror("Failed to init old project")
            return True
    elif projectType == PROJECT_TYPE_CCPN:
        project = Project.open(entryId, status='new')
        if not project.initCcpn(ccpnFolder=fileNameTgz, modelCount=modelCount):
            nTerror("Failed to init project from ccpn")
            return True
    elif projectType == PROJECT_TYPE_PDB:
        project = Project.open(entryId, status='new')
#        pdbFileFormats = [ entryId + ".pdb", "pdb" + entryId + ".ent.gz" ]
#        for pdbFileName in pdbFileFormats:
#        pdbFileName = "pdb" + entryId + ".ent.gz"
#        #    pdbFilePath = os.path.join( inputDir, pdbFileName)
#            pdbFilePath = os.path.join(inputDir, pdbFileName)
#            if os.path.exists(pdbFilePath):
#                break
#        tmpPdbFile = None
#        if pdbFileName.endswith('.gz'):
        pdbFilePath = entryId + ".pdb"
#        tmpPdbFile = pdbFilePath
#        if os.path.exists(pdbFilePath):
#            os.unlink(pdbFilePath)
        gunzip(fileNameTgz, outputFileName=pdbFilePath, removeOriginal=True)
        project.initPDB(pdbFile=pdbFilePath, convention=IUPAC, nmodels=modelCount)
#        if tmpPdbFile:
        if True:
            nTdebug("Removing tmp: %s" % pdbFilePath)
            os.unlink(pdbFilePath)

#    if inputDirOrg == inputDirCASD_NMR:
#    if True: # Default is False for this is specific to CASD-NMR
#        nTmessage("Renaming molecule name to entry id: %s" % entryId)
#        project.molecule.name = entryId # insufficient since all data is already initialized to disk.
#        project.molecule.rename( entryId )

#    project.save()
#    project.molecule.ranges = ranges # JFD: this doesn't seem to be set there exactly.
    project.molecule.superpose(ranges=ranges)
    if True:
        if project.validate(htmlOnly=htmlOnly, ranges=ranges, doProcheck=doProcheck, doWhatif=doWhatif,
                doWattos=doWattos, doTalos=doTalos):
            nTerror("Failed to validate project read")
            return True

    if storeCING2db:
        # Does require:
        #from cing.PluginCode.sqlAlchemy import csqlAlchemy
        # and should never crash  run.
        try:
            if doStoreCING2db( entryId, ARCHIVE_CASP_ID, project=project):
                nTerror("Failed to store CING project's data to DB but continuing.")
        except:
            nTtracebackError()
            nTerror("Failed to store CING project's data due to above traceback error.")

    project.save()
    if projectType == PROJECT_TYPE_CCPN:
#        fileNameTgz = entryId + '.tgz'
#        os.unlink(fileNameTgz) # temporary ccpn tgz
        rmdir(entryId) # temporary ccpn dir

    if tgzCing:
        directoryNameCing = entryId + ".cing"
        tgzFileNameCing = directoryNameCing + ".tgz"
        if os.path.exists(tgzFileNameCing):
            nTwarning("Overwriting: " + tgzFileNameCing)
        cmd = "tar -czf %s %s" % (tgzFileNameCing, directoryNameCing)
        do_cmd(cmd)
예제 #42
0
    def testResPlot(self):

        actuallyRunProcheck = False
        actuallyRunWhatif   = False
        showValues          = False
        modelNum            = 1 # Only used when simulating data
        #entryId = "1ai0" # Most complex molecular system in any PDB NMR entry
#        entryId = "2hgh" # Small much studied PDB NMR entry; 48 models
#        entryId = "1bus" # Small much studied PDB NMR entry:  5 models of 57 AA.: 285 residues.
        entryId = "1brv"

        ranges = None
        if entryId.startswith("2hgh"):
            # Compile a NTlist instance with residue objects.
            ranges = "2-54,111-136,145-193"
                # 1 and 55 are 5' and 3' terminii which are a little looser.
                # 12, and 34 are bases that are not basepaired.
                # 191-193 are bound ZN ions.
        elif entryId.startswith("1brv"):
            # Truncate from Val171-Glu189 to:
            ranges = "176-188"

        project = Project( entryId )
        project.removeFromDisk()
        project = Project.open( entryId, status='new' )
        cyanaFolder = os.path.join(cingDirTestsData,"cyana", entryId+".cyana.tgz")
        nTdebug("Reading files from: " + cyanaFolder)
        project.initCyana( cyanaFolder )
        project.runDssp()

        rangeList = project.molecule.getFixedRangeList(
            max_length_range = ResPlot.MAX_WIDTH_IN_RESIDUES, ranges=ranges )

        if actuallyRunProcheck:
            self.failIf(project.procheck(createPlots=False, runAqua=False) is None)
        if actuallyRunWhatif:
            self.assertFalse(runWhatif(project))

        pointsANGCHK = [] # list per res in rangeList of lists
        pointsBNDCHK = []
        pointsQUACHK = []
        pointsRAMCHK = []
        pointsC12CHK = []
        pointsBBCCHK = []
        resNumb = 0
        for resList in rangeList:
            for res in resList:
                resNumb += 1

    #            nTdebug(repr(res))

    #            if random() < 0.2: # Skip a 10%
    #                continue

                whatifResDict = res.setdefault(WHATIF_STR, NTdict())
                procheckResDict = res.setdefault(PROCHECK_STR, NTdict())
    #            if not whatifResDict: # empty dict
    #                continue

                angList = NTlist()
                bndList = NTlist()

                quaList = NTlist()
                ramList = NTlist()
                c12List = NTlist()
                bbcList = NTlist()

                accList = NTlist()
                sstList = NTlist()
                sstListPossibilities='SH' # secondary structure elements.

                for _modelID in range(modelNum):
                    if not actuallyRunWhatif:
                        angList.append(random()*10-0) # Simulate abs max of Z-scores.
                        bndList.append(random()*5+1)  # offset by 1 but still want to start from zero?

                        quaList.append(random()*5+1)
                        ramList.append(random()*5+1)
                        c12List.append(random()*5+1)
                        bbcList.append(random()*5+1)

                        accList.append(random()*4-2)
                    if not actuallyRunProcheck:
                        sstList.append( sstListPossibilities[ int(random()*2)])  # Simulate secondary structure

                if not actuallyRunWhatif:
                    self.assertFalse (   whatifResDict.setDeepByKeys(angList,  ANGCHK_STR,VALUE_LIST_STR) )
                    self.assertFalse (   whatifResDict.setDeepByKeys(bndList,  BNDCHK_STR,VALUE_LIST_STR) )

                    self.assertFalse (   whatifResDict.setDeepByKeys(quaList,  QUACHK_STR,VALUE_LIST_STR) )
                    self.assertFalse (   whatifResDict.setDeepByKeys(ramList,  RAMCHK_STR,VALUE_LIST_STR) )
                    self.assertFalse (   whatifResDict.setDeepByKeys(c12List,  C12CHK_STR,VALUE_LIST_STR) )
                    self.assertFalse (   whatifResDict.setDeepByKeys(bbcList,  BBCCHK_STR,VALUE_LIST_STR) )

                    self.assertFalse (   whatifResDict.setDeepByKeys(accList,  INOCHK_STR,VALUE_LIST_STR) )

                if not actuallyRunProcheck:
                    self.assertFalse ( procheckResDict.setDeepByKeys(sstList,  SECSTRUCT_STR) )

                for d in [whatifResDict, procheckResDict]:
                    checkIDList = d.keys()
                    for checkID in checkIDList:
                        if d==whatifResDict:
                            valueList = d.getDeepByKeys(checkID,VALUE_LIST_STR)
                        else:
                            valueList = d.getDeepByKeys(checkID)

                        if checkID == ANGCHK_STR:
                            zScore = valueList.average()[0]
                            pointsANGCHK.append( (resNumb-.5, zScore) )
                        elif checkID == BNDCHK_STR:
                            zScore = valueList.average()[0]
                            pointsBNDCHK.append( (resNumb-.5, zScore) )
                        elif checkID == QUACHK_STR:
                            zScore = valueList.average()[0]
                            pointsQUACHK.append( (resNumb-.5, zScore) )
                        elif checkID == RAMCHK_STR:
                            zScore = valueList.average()[0]
                            pointsRAMCHK.append( (resNumb-.5, zScore) )
                        elif checkID == C12CHK_STR:
                            zScore = valueList.average()[0]
                            pointsC12CHK.append( (resNumb-.5, zScore) )
                        elif checkID == BBCCHK_STR:
                            zScore = valueList.average()[0]
                            pointsBBCCHK.append( (resNumb-.5, zScore) )
#                            nTdebug("pointsBBCCHK: %s", pointsBBCCHK)

                        if showValues:
                            nTdebug("%10s valueList: %-80s" % ( checkID, valueList))
        fileNameList =[]
        ps = None
        r = 0
        for resList in rangeList:
            r += 1
#            nTdebug("resList: %s" % resList)
            ps = NTplotSet() # closes any previous plots
            ps.hardcopySize = (600,600)
            nrows = 2
            ntPlotList = []
            for i in range(nrows):
                ntPlotList.append( ps.createSubplot(nrows,1,i+1,useResPlot=True,molecule=project.molecule,resList=resList) )


            ps.subplotsAdjust(hspace  = .1) # no height spacing between plots.
            ps.subplotsAdjust(top     = 0.9) # Accommodate icons and res types.
            ps.subplotsAdjust(left    = 0.15) # Accommodate extra Y axis label.

            attr = fontVerticalAttributes()
            attr.fontColor  = 'blue'
            # Left of actual yLabel.
            labelAxesExtraList = [
              'Backbone',
              'Quality',
              'Angle',
              '',
              '' ]
            labelAxesList = [
              'Ramachandr. Z',
              'Chi 1/2. Z',
              'Bond max Z',
              'Restraint RMSD',
              '' ]
            for i in range(nrows):
                position = (-0.12, 0.5)
                ntPlotList[i].labelAxes( position, labelAxesExtraList[i], attributes=attr)
                ntPlotList[i].yLabel = labelAxesList[i]
                if i != nrows-1:
                    ntPlotList[i].xLabel = None



            plusPoint   = pointAttributes( type='plus',   size=1.5, color='black' )
            circlePoint = pointAttributes( type='circle', size=1.5, color='blue')
            plusPoint.lineColor   = 'black'
            circlePoint.lineColor = 'blue'
            length = ntPlotList[0].MAX_WIDTH_IN_RESIDUES
            start = (r-1)*length

#            pointsBBCCHK = removeNulls(pointsBBCCHK)
            # buildin max is overridden by matplotlib
#            end   = NTmin(start + ntPlot1.MAX_WIDTH_IN_RESIDUES,len(pointsANGCHK))
            pointsANGCHKOffset = convertPointsToPlotRange(pointsANGCHK, xOffset=-start, yOffset=0, start=0, length=length)
            pointsBNDCHKOffset = convertPointsToPlotRange(pointsBNDCHK, xOffset=-start, yOffset=0, start=0, length=length)
            pointsQUACHKOffset = convertPointsToPlotRange(pointsQUACHK, xOffset=-start, yOffset=0, start=0, length=length)
            pointsRAMCHKOffset = convertPointsToPlotRange(pointsRAMCHK, xOffset=-start, yOffset=0, start=0, length=length)
            pointsC12CHKOffset = convertPointsToPlotRange(pointsC12CHK, xOffset=-start, yOffset=0, start=0, length=length)
            pointsBBCCHKOffset = convertPointsToPlotRange(pointsBBCCHK, xOffset=-start, yOffset=0, start=0, length=length)

            pointsOffsetList = [pointsRAMCHKOffset,
                                pointsQUACHKOffset,
                                pointsANGCHKOffset ]
            pointsOffsetList2 = [pointsBBCCHKOffset,
                                 pointsC12CHKOffset,
                                 pointsBNDCHKOffset ]
#            nTdebug("pointsRAMCHKOffset: %s" % pointsRAMCHKOffset)
#            nTdebug("start:end: %s %s" % (start,end))
            for i in range(nrows):
                if i >= len( pointsOffsetList ):
                    continue
                ntPlotList[i].lines(pointsOffsetList[i],  plusPoint)
                ntPlotList[i].lines(pointsOffsetList2[i], circlePoint)
                ntPlotList[i].autoScaleY( pointsOffsetList[i]+pointsOffsetList2[i] )
                if i == 2: # by chance
                    ntPlotList[i].setYrange((.0, ntPlotList[i].yRange[1]))

            ySpaceAxisResTypes = .02 + (nrows-1) * .01
            ntPlotList[0].drawResTypes(ySpaceAxis=ySpaceAxisResTypes) # Weirdly can only be called after yRange is set.

            for i in range(nrows):
                showLabels = False
                if i == nrows-1:
                    showLabels = True
                # also sets the grid lines for major. Do last as it won't rescale with plot yet.
                ntPlotList[i].drawResNumbers( showLabels=showLabels)

            # Draw secondary structure elements and accessibility
            # Set x range and major ticker.
            # The major ticker determines the grid layout.
            # leave space for res types but get it right on top.
#            .18 at nrows = 4
            # Needs to be done before re-scaling the y axis from [0,1] ???????
            ySpaceAxisResIcons = .06 + (nrows-1) * .04
            ntPlotList[0].iconBoxYheight = 0.16 * nrows / 3. # .16 at nrows=3
            ntPlotList[0].drawResIcons( ySpaceAxis=ySpaceAxisResIcons )

            # Set the grid and major tickers
            fileNameList.append( 'residuePlotSet%03d.pdf' % r)
            ps.hardcopy(fileNameList[r-1])
        # end for resList in rangeList:
        self.assertFalse( joinPdfPages( fileNameList, 'residuePlotSetAll.pdf' ))
        for fileName in fileNameList:
            os.unlink( fileName )