def readSummary(self, fix=False): path = self.path(self.entryName, 'Cing', 'CingSummaryDict.xml') if not path.exists(): print 'Error Entry.readSummary: file %s does not exist' % path return None nTmessage( '==> reading summary from %s', path ) self.cingSummary = xML2obj(path) if fix: rog = NTlist( 0, 0, 0 ) # Counts for red, orange, green. for resname, rogScore in self.cingSummary.CING_residueROG: print resname, rogScore if rogScore.isRed(): rog[0] += 1 elif rogScore.isOrange(): rog[1] += 1 else: rog[2] += 1 #end for total = reduce(lambda x, y: x+y+0.0, rog) # total expressed as a float because of 0.0 print rog, total for i, _x in enumerate(rog): rog[i] = rog[i]*100.0/total self.cingSummary.cing_red = round(rog[0],1) self.cingSummary.cing_orange = round(rog[1],1) self.cingSummary.cing_green = round(rog[2],1) #end if #copy the data for par in cingPars: if par in self.cingSummary: self[par] = self.cingSummary[par] return self.cingSummary
def restoreStereoAssignments( molecule, stereoFileName ): """ Restore the stereo assignments from xml stereoFileName, return count or -1 on error """ if not os.path.exists( stereoFileName ): return -1 stereo = xmlTools.xML2obj(stereoFileName) if stereo is None: io.error('restoreStereoAssignment: parsing xml-file "{0}"\n', stereoFileName) return -1 #end if count = 0 for nameTuple in stereo: atm = molecule.decodeNameTuple( nameTuple ) if atm is None: io.error('restoreStereoAssignment: invalid atom nameTuple ({0})', nameTuple) else: atm.stereoAssigned = True count += 1 #end if #end for #nTdebug('Molecule.restoreStereoAssignments: restored %d stereo assignments from "%s\n',count, stereoFileName) return count
def restoreSequence( molecule, sequenceFile ): """Restore sequence from sequenceFile. Return self or None on error. """ if (not os.path.exists( sequenceFile ) ): io.error('Molecule.restoreSequence: sequenceFile "{0}" not found\n', sequenceFile ) return None #end if # compatibility if molecule.content.version < 0.92: fileObject = open(sequenceFile, 'r') for line in fileObject: exec(line) #end for fileObject.close() else: sequence = xmlTools.xML2obj( sequenceFile ) if sequence is None: io.error('restoreSequence: error parsing xml-file "{0}"', sequenceFile) return None for chainId, resName, resNum, convention in sequence: molecule.addResidue( chainId, resName, resNum, convention ) #end for #end if return molecule
def restoreShiftx100(project): """ Restore shiftx results by parsing files. Return True on error """ if project is None: nTdebug("restoreShiftx100: No project defined") return True if project.molecule == None: return True # Gracefully returns defs = project.getStatusDict(constants.SHIFTX_KEY) # Older versions; initialize the required keys of shiftx Status from xml file if project.version < 0.881: path = project.validationPath(cdefs.validationsDirectories.shiftx) if not path: nTerror('restoreShiftx100: directory "%s" with shiftx data not found', path) return True xmlFile = project.path() / 'content.xml' if not xmlFile.exists(): nTerror('restoreShiftx100: Shiftx results xmlFile "%s" not found', xmlFile) return True #end if shiftxResult = xmlTools.xML2obj(xmlFile) if not shiftxResult: nTerror('restoreShiftx100: restoring Shiftx results from xmlFile "%s" failed', xmlFile) return None defs.update(shiftxResult) defs.completed = True #end if #update some of the settings if 'moleculeName' in defs: del defs['moleculeName'] if 'path' in defs: defs.directory = disk.Path(defs.path)[-1:] del defs['path'] else: defs.directory = constants.SHIFTX_KEY if 'contenFile' in defs: del defs['contentFile'] if not defs.completed: nTdebug('restoreShiftx100: shiftx not completed') return True return project.parseShiftx()
def restore(path=None): if path == None: path = analysisPath / 'results.xml' tmp = xML2obj(path) if not tmp: return 1 results = ResultsList(dataPath=path[:-1]) for entry in tmp: # replace keyword if entry.has_key('programType'): entry['method'] = entry['programType'] del entry['programType'] if entry['method'] == 'None' and entry['group'] == 'Org': entry['method'] = 'Original' results.append(entry) return results
def openMol_075( path ) : """Static method to restore molecule from directory path implements the <=0.75 storage model returns Molecule instance or None on error """ # old format content = xmlTools.xML2obj( path=os.path.join( path, NTmolParameters.contentFile ) ) if not content: io.error('openMol_075: error reading xml file "{0}"\n', os.path.join( path, NTmolParameters.contentFile ) ) return None #end if content.keysformat() io.debug('openMol_075: content from xml-file: %s', content.format()) mol = molecule.Molecule( name = content.name ) if not mol: io.error('openMol_075: initializing molecule\n') return None #end if mol.content = content if content.has_key('sequenceFile') and \ restoreSequence(mol, os.path.join(path, content.sequenceFile)) is None: return None if content.has_key('resonanceFile') and \ restoreResonances(mol, os.path.join(path, content.resonanceFile), append=False) < 0: return None if content.has_key('stereoFile') and \ restoreStereoAssignments(mol, os.path.join(path, content.stereoFile)) < 0: return None if content.has_key('coordinateFile') and \ restoreCoordinates(mol, os.path.join(path, content.coordinateFile), append=False) is None: return None mol._check() mol.updateAll() return mol
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