def run(): parser = getRefineParser() (options, _args) = parser.parse_args() if options.verbosity >= 0 and options.verbosity <= 9: cing.verbosity = options.verbosity else: nTerror("set verbosity is outside range [0-9] at: " + options.verbosity) nTerror("Ignoring setting") # end if # From this point on code may be executed that will go through the appropriate verbosity filtering nTdebug("options: %s" % str(options)) #------------------------------------------------------------------------------ # Documentation #------------------------------------------------------------------------------ if options.doc: parser.print_help(file=sys.stdout) nTmessage("%s\n", __doc__) return #end if #------------------------------------------------------------------------------ #check for the required project, name option parser.check_required('--name') parser.check_required('--project') project = Project.open(options.project, status='old', restore=1) #DEFAULT 0 if project == None: nTerror("Failed to get a project") return True #end if basePath = project.path(project.directories.refine, options.name) # nTdebug("basePath: " + basePath) #------------------------------------------------------------------------------ # Setup #------------------------------------------------------------------------------ parameters = None if options.doSetup: parameters = doSetup(config, project, basePath, options) # return # We had like to continue in new setup. So don't exit here. #end if #------------------------------------------------------------------------------ # Some output #------------------------------------------------------------------------------ nTmessage("==> Reading configuration") nTmessage('refinePath: %s', config.refinePath) nTmessage('xplor: %s', config.XPLOR) nTmessage("parameterFiles: %s", config.parameterFiles) nTmessage("topologyFiles: %s", config.topologyFiles) if (options.fullRefine or options.fullAnneal or options.fullAnnealAndRefine): if options.doSetup: nTerror( "Setup was done but fullXXX would do it again. Just run fullXXXX again without setup please." ) sys.exit(1) # end if else: #------------------------------------------------------------------------------ # read parameters file #------------------------------------------------------------------------------ if not parameters: # nTdebug('==> will read parameters') parameters = getParameters(basePath, 'parameters') # nTdebug('==> parameters\n%s\n', str(parameters)) nTmessage('==> Read parameters') # end if setParametersFromOptions( project, options, parameters ) # Do here for the first time and every time refine is called. nTmessage( '==> Done transferring some options from commandline to parameters (again)' ) parameters.basePath = basePath if parameters.name != options.name: nTwarning("parameters.name (%s) != options.name (%s)" % (parameters.name, options.name)) # end if # end if #------------------------------------------------------------------------------ # Action selection #------------------------------------------------------------------------------ if options.doPSF: generatePSF(config, project, parameters, options.doPrint) elif options.generateTemplate: generateTemplate(config, project, parameters, options.doPrint) elif options.doAnneal: anneal(config, project, parameters, options.doPrint) elif options.doAnalyze: analyze(config, project, parameters, options.doPrint) elif options.doRefine: refine(config, project, parameters, options.doPrint) elif options.doParse: _results = parseOutput(config, project, parameters) elif options.doImport: importFrom(config, project, parameters) elif options.fullAnneal: if not fullAnneal(config, project, options): nTerror("Failed fullAnneal") elif options.fullRefine: if not fullRefine(config, project, parameters, options): nTerror("Failed fullRefine") elif options.fullAnnealAndRefine: if not fullAnnealAndRefine(config, project, options): nTerror("Failed fullAnnealAndRefine") else: if not options.doSetup: nTerror('refine.py, invalid options combinations:\n%s' % str(options)) return True else: nTmessage("Done after setup.") #end if if options.ipython: startIpythonShell()
def yasaraShell(project): if not cing.yasaradir: nTcodeerror('yasaraShell: please put a proper yasara.py module on PYTHONPATH first (check yasaradir!)') exit(1) # shortcuts f = pformat #@UnusedVariable # pylint: disable=W0612 p = project #@UnusedVariable # pylint: disable=W0612 mol = project.molecule #@UnusedVariable # pylint: disable=W0612 def commands(): # pylint: disable=W0612 cmds = ['commands', 'colorByResidue', 'colorGF', 'colorJanin', 'colorROG', 'colorWhatif', 'getSelectedResidue', 'hud', 'loadPDB', 'screenDump', 'showHtml'] cmds.sort() for c in cmds: nTmessage( c ) #end for #end def def loadPDB(model = None): """ Load project.molecule model [0,modelCount-1] or all models if None """ if not project.molecule: nTerror('loadPDB: no molecule defined') return True if model == None or model == 'all': path = project.moleculePath('yasara', sprintf('%s.pdb', project.molecule.name)) model = None else: path = project.moleculePath('yasara', sprintf('%s_%s.pdb', project.molecule.name, model)) project.molecule.toPDBfile(path, model = model) nTmessage('loadPDB: %s' % path) LoadPDB(os.path.abspath(path)) Style('Ribbon', 'off') #end def # alternate names loadpdb = loadPDB #@UnusedVariable # pylint: disable=W0612 loadPdb = loadPDB #@UnusedVariable # pylint: disable=W0612 def colorROG(object = 1): # pylint: disable=W0612 """ Color residues according to Cing ROG score """ Console('off') ColorRes('object ' + str(object), 'Gray') yasaraColorDict = dict(green = 240, orange = 150, red = 120) for res in project.molecule.allResidues(): cmd = sprintf('object %s residue %d,%s', object, res.resNum, yasaraColorDict[res.rogScore.colorLabel]) ColorRes(cmd) #end for Console('on') #end def def colorGF(object = 1, minValue = -3.0, maxValue = 1.0): # pylint: disable=W0612 """ Color residues according to Procheck gf score """ colorByResidue(['procheck', 'gf'], minValue = minValue, maxValue = maxValue, reverseColorScheme = True ) #end def def colorWhatif(checkId, object = 1, minValue = -4.0, maxValue = 1.0, reverseColorScheme = True): """ Color according to Whatif checkId score """ Console('off') objectStr = 'object ' + str(object) ColorRes(objectStr, 'Gray') PropRes(objectStr, -999) if reverseColorScheme: ColorPar('Property ', 'Min', 'red', minValue) ColorPar('Property ', 'Max', 'blue', maxValue) else: ColorPar('Property ', 'Min', 'blue', minValue) ColorPar('Property ', 'Max', 'red', maxValue) for res in project.molecule.allResidues(): list = getDeepByKeysOrAttributes(res, WHATIF_STR, checkId, VALUE_LIST_STR) if list: value, _sd, _n = list.average() if value != None and not isNaN(value): PropRes(sprintf('object %s Residue %d', object, res.resNum), value) #end if #end if #end for ColorRes(objectStr, 'Property') Console('on') #end def def colorRama(object = 1): # pylint: disable=W0612 """ Color according to Whatif ramachandran score """ colorWhatif('ramachandran', object = object, minValue = -1.5, maxValue = 1.0) def colorJanin(object = 1): # pylint: disable=W0612 """ Color according to Whatif janin score """ colorWhatif('janin', object = object, minValue = -1.5, maxValue = 1.0) def colorByResidue(keys, object = 1, minValue = 0.0, maxValue = 1.0, reverseColorScheme = False ): Console('off') objectStr = 'object ' + str(object) ColorRes(objectStr, 'Gray') PropRes(objectStr, -999) #end if if reverseColorScheme: ColorPar('Property ', 'Min', 'red', minValue) ColorPar('Property ', 'Max', 'blue', maxValue) else: ColorPar('Property ', 'Min', 'blue', minValue) ColorPar('Property ', 'Max', 'red', maxValue) for res in project.molecule.allResidues(): value = getDeepByKeysOrAttributes(res, *keys) # if res.has_key(property) and res[property] != None and not isNaN(res[property]): if value != None and not isNaN(value): PropRes(sprintf('object %s Residue %d', object, res.resNum), value) #end for ColorRes(objectStr, 'Property') Console('on') #end def def getSelectedResidue(): """ Get the residue that is selected in yasara """ atomId = MarkAtom()[0] if int(atomId) == 0: nTerror('getSelectedResidue: nothing selected') return None a = Atom('atom ' + str(atomId)) fields = str(a).split() atmName = fields[2] resName = fields[3] chainName = fields[4] resNum = int(fields[5]) nTmessage( 'Selected:', chainName, resName, resNum, atmName ) nameTuple = (project.molecule.name, chainName, resNum, None, None, None, IUPAC) #print nameTuple res = project.molecule.decodeNameTuple(nameTuple) #print res return res #end def def showHtml(): """ Show the html page of the selected residue """ res = getSelectedResidue() if not res: nTerror('showHtml: invalid residue') path = os.path.abspath(project.htmlPath('Molecule', res.chain.name, res.name, 'index.html')) nTmessage( 'showHtml: %s' % path ) webbrowser.open('file://' + path) #@UndefinedVariable #end def showhtml = showHtml #@UnusedVariable # pylint: disable=W0612 def screenDump(fileName, hideHUD = True): """ Make a screen dump; optionally hide HUD temporarily (default True) """ path = project.moleculePath('yasara', fileName) if hideHUD: hud('off') nTmessage( 'screenDump to: %s' % path ) SaveBmp(path) hud('on') #end def screendump = screenDump #@UnusedVariable # pylint: disable=W0612 def hud(toggle): """ Toggle HUD on/off """ if toggle == 'off': HUD('off', 'on') else: HUD('obj', 'on') #end def startIpythonShell( in_template = sprintf('yasara (%s) \#> ', project.name), banner = '--------Dropping to yasara--------', exit_msg='--------Leaving yasara--------' )
def run(): parser = getRefineParser() (options, _args) = parser.parse_args() if options.verbosity >= 0 and options.verbosity <= 9: cing.verbosity = options.verbosity else: nTerror("set verbosity is outside range [0-9] at: " + options.verbosity) nTerror("Ignoring setting") # end if # From this point on code may be executed that will go through the appropriate verbosity filtering nTdebug("options: %s" % str(options)) #------------------------------------------------------------------------------ # Documentation #------------------------------------------------------------------------------ if options.doc: parser.print_help(file=sys.stdout) nTmessage("%s\n", __doc__) return #end if #------------------------------------------------------------------------------ #check for the required project, name option parser.check_required('--name') parser.check_required('--project') project = Project.open(options.project, status='old', restore=1) #DEFAULT 0 if project == None: nTerror("Failed to get a project") return True #end if basePath = project.path(project.directories.refine, options.name) # nTdebug("basePath: " + basePath) #------------------------------------------------------------------------------ # Setup #------------------------------------------------------------------------------ parameters = None if options.doSetup: parameters = doSetup(config, project, basePath, options) # return # We had like to continue in new setup. So don't exit here. #end if #------------------------------------------------------------------------------ # Some output #------------------------------------------------------------------------------ nTmessage("==> Reading configuration") nTmessage('refinePath: %s', config.refinePath) nTmessage('xplor: %s', config.XPLOR) nTmessage("parameterFiles: %s", config.parameterFiles) nTmessage("topologyFiles: %s", config.topologyFiles) if ( options.fullRefine or options.fullAnneal or options.fullAnnealAndRefine): if options.doSetup: nTerror("Setup was done but fullXXX would do it again. Just run fullXXXX again without setup please.") sys.exit(1) # end if else: #------------------------------------------------------------------------------ # read parameters file #------------------------------------------------------------------------------ if not parameters: # nTdebug('==> will read parameters') parameters = getParameters( basePath, 'parameters') # nTdebug('==> parameters\n%s\n', str(parameters)) nTmessage('==> Read parameters') # end if setParametersFromOptions(project, options, parameters) # Do here for the first time and every time refine is called. nTmessage('==> Done transferring some options from commandline to parameters (again)') parameters.basePath = basePath if parameters.name != options.name: nTwarning("parameters.name (%s) != options.name (%s)" % ( parameters.name, options.name) ) # end if # end if #------------------------------------------------------------------------------ # Action selection #------------------------------------------------------------------------------ if options.doPSF: generatePSF(config, project, parameters, options.doPrint) elif options.generateTemplate: generateTemplate(config, project, parameters, options.doPrint) elif options.doAnneal: anneal(config, project, parameters, options.doPrint) elif options.doAnalyze: analyze(config, project, parameters, options.doPrint ) elif options.doRefine: refine(config, project, parameters, options.doPrint) elif options.doParse: _results = parseOutput(config, project, parameters) elif options.doImport: importFrom(config, project, parameters) elif options.fullAnneal: if not fullAnneal(config, project, options): nTerror("Failed fullAnneal") elif options.fullRefine: if not fullRefine(config, project, parameters, options): nTerror("Failed fullRefine") elif options.fullAnnealAndRefine: if not fullAnnealAndRefine( config, project, options): nTerror("Failed fullAnnealAndRefine") else: if not options.doSetup: nTerror('refine.py, invalid options combinations:\n%s' % str(options)) return True else: nTmessage("Done after setup.") #end if if options.ipython: startIpythonShell()