Esempio n. 1
0
def upgrade075(project, restore):
    """
    Upgrade project from 075 or earlier conventions
    return upgraded project or None on error
    """
    io.message('upgrade075: converting from CING version {0}\n', project.version)

    # 0.75 version had moleculeNames stored in molecules attribute
    # >=0.76 version molecules is a ProjectList instance
    project.moleculeNames = project.molecules

    # store the project file and reopen to have correct settings
    project._save2json()
    pr = classes.Project._restoreFromJson(project.path(cing.cingPaths.project))
    if pr == None:
        io.error('upgrade075: conversion from version %s failed on read\n', project.version)
        return None

    for molName in pr.moleculeNames:
        pathName = pr.path(cing.directories.molecules, molName) # old reference, versions 0.48-0.75
        if pr.version <= 0.48:
            pathName = pr.path('Molecules', molName) # old reference
        # end if
        io.debug('upgrade075: trying molecule conversion from {0}\n', pathName)
        if not pathName.exists():
            io.error('upgrade075: old molecule pathName "{0}" does not exist\n', pathName)
            return None
        mol = openMol_075(pathName)
        if not mol:
            io.error('upgrade075: conversion from version {0} failed on molecule {1}\n', project.version, molName)
            return None
        pathName.removedir()
        # Save molecule to new format
        mol.save(pr.molecules.path(molName))
    #end for

    # restore
    pr.restore()
    # Save to consolidate
    pr.save()

    return cing.Legacy.Legacy100.upgrade100.upgrade100(pr, restore)
Esempio n. 2
0
def setup_DummyProject():
    global theProject
    os.chdir(cdefs.cingDefinitions.tmpdir)
    print('Now in %s' % cdefs.cingDefinitions.tmpdir)
    theProject = Project.new(TEST)
    # create a molecule
    mol = molecule.Molecule(TEST)
    theProject.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=constants.INTERNAL_0, Nterminal = True)
    c.addResidue('RADE', 2, convention=constants.INTERNAL_0)
    c.addResidue('URA', 3, convention=constants.INTERNAL_0) # not RTHY normally of course.
    c.addResidue('RTHY', 4, convention=constants.INTERNAL_0)
    c.addResidue('RCYT',  5, convention=constants.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()
    io.message('{0}\n',mol.format())
Esempio n. 3
0
def upgradeProject2Json( name, restore  ):
    """Upgrade the project from project.xml to project.json file
    Convert several parameters to new Adict types
    """
    io.debug('upgradeToJson: restoring {0}\n', name)

    root, newName, ext = Project.rootPath(name)
    if not root:
        io.error('upgradeToJson: unable to open Project "{0}" because root is [{1}]\n', name, root)
        return None
    if not root.exists():
        io.error('upgradeToJson: unable to open Project "{0}" because root [{1}] was not found\n', name, root)
        return None
    #end if

    pfile = root / 'project.xml' # Name in all versions <= 1.0
    # Check if we find the xml file
    if pfile.exists():
        io.message('==> Upgrading cing project; please stand by\n')
        #GWV: 20140203: cannot do an update method() -> errors in partioning restraints. Do not understand
        pr = xmlTools.xML2obj(pfile)

        if pr is None:
            io.error('upgradeToJson: parsing from project file "{0}" failed\n', pfile)
            return None

        try:
            # <= 0.75 version have string
            pr.version = float(pr.version.strip('abcdefghijklmnopqrtsuvw ()!@#$%^&*').split()[0])
        except:
            pass

        # change to Time object
        pr.created = io.Time.fromString(pr.created)
        pr.lastSaved = io.Time(disk.modtime(pfile))

        # change types of names list
        for listName in 'moleculeNames peakListNames distanceListNames dihedralListNames rdcListNames'.split():
            #print 'listName>>',listName, (listName in pr)
            if listName in pr:
                pr[listName] = [n for n in pr[listName]]

        # update from old status type
        status = Adict()
        for key in constants.VALIDATION_KEYS:
            sdict = StatusDict(key)
            status[key] = sdict
            # if not isinstance(sdict, StatusDict):
            #     sdict = StatusDict(key)
            if key in pr.status:
                # print 'upgrade2json> key=', key
                # not certain if we get dict or NTdict; this circumvent unwanted keys of NTdict
                for k,v in pr.status[key].items():
                    #print 'upgrade2json>> k,v', k,v
                    sdict[k] = v
                #print '>>>\n', sdict.formatItems()
            #end if
        #end for

        #end for
        # update the status from old definitions;
        for (key, statusName) in [
                (constants.SHIFTX_KEY, 'shiftxStatus'),
                (constants.PROCHECK_KEY,'procheckStatus'),
                (constants.DSSP_KEY, 'dsspStatus'),
                (constants.WHATIF_KEY, 'whatifStatus'),
                (constants.WATTOS_KEY, 'wattosStatus'),
                (constants.VASCO_KEY, 'vascoStatus'),
                (constants.X3DNA_KEY, 'x3dnaStatus')
            ]:
            sdict = status[key]
            if statusName in pr:

                #print 'upgrade2json> statusName=', statusName

                # not certain if we get dict or NTdict; this circumvent unwanted keys of NTdict
                for k,v in pr[statusName].items():
                    #print 'upgrade2json>> k,v=', k,v
                    sdict[k] = v
                #print '>>>\n', sdict.formatItems()
            #end if
            #LEGACY names
            pr[statusName] = sdict
        #end for
        # update some fields if present
        for sdict in status.values():
            if 'molecule' in sdict and isinstance(sdict['molecule'], tuple):
                sdict['molecule'] = pid.Pid.new('Molecule:' + sdict['molecule'][0])
            if 'moleculeName' in sdict and isinstance(sdict['molecule'], tuple):
                sdict['molecule'] = pid.Pid.new('Molecule:' + sdict['moleculeName'][0])
                del sdict['moleculeName']
            if 'runVersion' in sdict:
                sdict['version'] = sdict['runVersion']
                del sdict['runVersion']
            if 'smlFile' in sdict:
                del sdict['smlFile']
#            sdict['date'] = io.Time(1360158182.7)  # Wed Feb  6 13:43:02 2013
            sdict['date'] = io.Time(pr.lastSaved) # make a copy because otherwise the json handler breaks
            sdict['version'] = 0.95  # old version
        #end for
        # make this the new status dict
        pr.status = status

        #print '>>>>>\n', pr.status.queeny.formatItems()

        pr._save2json()
        # have to make the directory because we have not yet fully initialised all directories at this stage
        pr._updateProjectPaths()
        disk.rename(pfile, pr.path() / cdefs.directories.version1 / 'project.xml' )
        #now we should be able to open it again
        return Project.open( name, status = constants.PROJECT_OLD, restore = restore )

    else:
        io.error('upgradeToJson: missing Project file "{0}"\n', pfile)
        return None