示例#1
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())
示例#2
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()
示例#3
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
示例#4
0
文件: BMRB.py 项目: VuisterLab/cing
def initBMRB(project, bmrbFile, moleculeName=None):
    """
        Initialize from edited BMRB file
        Return molecule instance
    """
    mol = Molecule(name=moleculeName)
    project.appendMolecule(mol)

    error = False
    record = None
    for record in AwkLike(bmrbFile, minNF=8, commentString='#'):

        resName = record.dollar[3]
        resNum = record.int(2)

        atomName = record.dollar[4]
        #        shift   = record.float(6)
        #        serror  = record.float(7)
        #        ambig   = record.int(8)
        res = mol.addResidue(Chain.defaultChainId, resName, resNum, IUPAC)

        if (not res):
            nTerror('Error initBMRB: invalid residue %s %s line %d (%s)\n',
                    resName, atomName, record.NR, record.dollar[0])
            error = True
        #end if
    #end for

    error = error or (project.importBMRB(bmrbFile) == None)
    if error:
        nTmessage('==> initBMRB: completed with error(s)')
    else:
        nTmessage('==> initBMRB: successfully parsed %d lines from %s',
                  record.NR, record.FILENAME)
    #end if
    nTmessage("%s", mol.format())

    if error:
        return None
    return mol
示例#5
0
    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()
示例#6
0
    def initMolecule(self, moleculeName):
        """Initialize new Molecule instance from the tree.
        Return Molecule on None on error.
        """
        mol = Molecule(name=moleculeName)

        # The self.tree contains a tree-like representation of the pdb-records
        for ch in self.tree:
            chain = mol.addChain(name=ch.name)
            for res in ch:
                #                print '>', ch, res, res.skip, res.db
                if not res.skip and res.db != None:
                    residue = chain.addResidue(res.db.name, res.resNum)
                    if residue == None:
                        nTerror("Not adding residue: %s" % res)
                        continue
                    residue.addAllAtoms()
                #end if
            #end for
        #end for
#        nTdebug('pdbParser.initMolecule: %s', mol)
        self.map2molecule(mol)
        return mol