コード例 #1
0
ファイル: __init__.py プロジェクト: jakesyl/cing
def obj2json(obj, path, **metadata):
    """serialise object to json file"""
    from cing.Libs.disk import Path

    p = Path(str(path))  # assure path instance
    root, f, ext = p.split3()
    root.makedirs()
    with open(p,'w') as fp:
        fp.write(encode(obj, path=str(path), timestamp=str(io.now()), **metadata))
コード例 #2
0
ファイル: queeny.py プロジェクト: jakesyl/cing
def _runQueeny( project, tmp=None ):
    """Perform a queeny analysis and save the results.

    Returns True on error.
    Returns False when all is fine.
    """
    nTmessage("==> Calculating restraint information by Queeny")
    if project is None:
        nTerror("runQueeny: No project defined")
        return True

    if project.molecule is None:
        nTerror("runQueeny: No molecule defined")
        return True

    if len(project.distances) == 0:
        nTmessage("==> runQueeny: No distance restraints defined.")
        return True

    queenyDefs = project.getStatusDict(constants.QUEENY_KEY, **queenyDefaults())
    queenyDefs.molecule = project.molecule.asPid

    path = project.validationPath( queenyDefs.directory )
    if not path:
        nTmessage("==> runQueeny: error creating '%s'", path)
        return True

    q = Queeny( project )
    q.execute()
    queenyDefs.date = io.now()
    queenyDefs.completed = True
    queenyDefs.parsed = True
    queenyDefs.version = __version__

    del(q)

    return False
コード例 #3
0
ファイル: shiftx.py プロジェクト: jakesyl/cing
def runShiftx(project, parseOnly=False, model=None):
    """
    Use shiftx program to predict chemical shifts
    Works only for protein residues.

    Adds ShiftxResult instance to validation container of atoms
    LEGACY:
    Adds a NTlist object with predicted values for each model as shiftx attribute
    to each atom for which there are predictions, or empty list otherwise.

    Throws warnings for non-protein residues.
    Returns True on error.

    Shiftx works on pdb files, uses only one model (first), so we have to write the files separately and analyze them
    one at the time.
    """

    # LEGACY:
    if parseOnly:
        return parseShiftx(project)

    if cdefs.cingPaths.shiftx is None:
        nTmessage("runShiftx: no shiftx executable, skipping")
        return False  # Gracefully return

    if project.molecule is None:
        nTerror("runShiftx: no molecule defined")
        return True

    if project.molecule.modelCount == 0:
        nTwarning('runShiftx: no models for "%s"', project.molecule)
        return True

    if model is not None and model >= project.molecule.modelCount:
        nTerror('runShiftx: invalid model (%d) for "%s"', model, project.molecule)
        return True

    if not project.molecule.hasAminoAcid():
        nTmessage("==> Skipping runShiftx because no amino acids are present.")
        return False

    nTmessage("==> Running shiftx")

    skippedAtoms = []  # Keep a list of skipped atoms for later
    skippedResidues = []  # Only used for presenting to end user not actually used for skipping.
    skippedChains = []

    for chain in project.molecule.allChains():
        skippChain = True
        for res in chain.allResidues():
            if not res.hasProperties("protein"):
                if not res.hasProperties("HOH"):  # don't report waters
                    skippedResidues.append(res)
                for atm in res.allAtoms():
                    atm.pdbSkipRecord = True
                    skippedAtoms.append(atm)
                # end for
            else:
                skippChain = False
            # end if
            if skippChain:
                skippedChains.append(chain)
        # end for
    # end for
    if skippedResidues:
        nTmessage("==> runShiftx: %s non-protein residues will be skipped." % len(skippedResidues))

    defs = project.getStatusDict(constants.SHIFTX_KEY, **shiftxStatus())
    if model is not None:
        defs.models = NTlist(model)
    else:
        defs.models = NTlist(*range(project.molecule.modelCount))
    defs.baseName = "model_%03d"
    defs.completed = False
    defs.parsed = False
    defs.chains = []

    # initialize the shiftx attributes
    _resetShiftx(project)

    path = project.validationPath(defs.directory)
    if not path:
        return True
    if path.exists():
        nTdebug("runShiftx: removing %s with prior data", path)
        path.rmdir()
    path.makedirs()

    doShiftx = ExecuteProgram(pathToProgram=cdefs.cingPaths.shiftx, rootPath=path, redirectOutput=False)
    startTime = io.now()

    for model in defs.models:
        # set filenames
        rootname = defs.baseName % model
        nTdebug("runShiftx: doing model %s, path %s, rootname %s", model, path, rootname)

        # generate a pdbfile
        pdbFile = project.molecule.toPDB(model=model, convention=constants.IUPAC)
        if not pdbFile:
            nTerror("runShiftx: Failed to generate a pdb file for model: %s", model)
            return True
        pdbFile.save(path / rootname + ".pdb")
        del pdbFile

        for chain in project.molecule.allChains():
            if chain not in skippedChains:
                # nTdebug('Doing chain code [%s]' % (chain.name))
                # quotes needed because by default the chain id is a space now.
                # chainId =  "'" + chain.name + "'"
                # According to the readme in shiftx with the source this is the way to call it.
                chainId = "1" + chain.name
                outputFile = rootname + "_" + chain.name + ".out"
                defs.chains.append((chain.name, outputFile))
                doShiftx(chainId, rootname + ".pdb", outputFile)
            # end if
        # end for
    # end for

    # cleanup
    for pdbfile in path.glob("*.pdb"):
        pdbfile.remove()

    # Restore the 'default' state
    for atm in skippedAtoms:
        atm.pdbSkipRecord = False

    defs.completed = True
    # parse the results
    if parseShiftx(project):
        return True

    defs.date = io.now()
    defs.version = __version__
    defs.molecule = project.molecule.asPid
    defs.remark = "Shiftx on %s completed in %.1f seconds on %s; data in %s" % (
        project.molecule,
        defs.date - startTime,
        defs.date,
        path,
    )
    project.history(defs.remark)
    nTmessage("==> %s", defs.remark)
    return False
コード例 #4
0
ファイル: talosPlus.py プロジェクト: jakesyl/cing
def runTalosPlus(project, tmp=None, parseOnly=False):
    """Perform a talos+ analysis; parses the results; put into new CING dihedral restraint list
    Returns True on error.
    Returns False when talos is absent or when all is fine.
    """
    #LEGACY:
    if parseOnly:
        return parseTalosPlus(project)

    if project is None:
        nTerror("runTalosPlus: No project defined")
        return True

    # check executable
    if cdefs.cingPaths.talos is None:
        nTmessage('runTalosPlus: no talosPlus executable defined, skipping')
        return False # Gracefully return
    status, output = getOsResult('which '+ cdefs.cingPaths.talos )
    if len(output) == 0:
        nTmessage('runTalosPlus: invalid talosPlus executable defined (%s), skipping', cdefs.cingPaths.talos)
        return False # Gracefully return

    if project.molecule is None:
        nTmessage("runTalosPlus: No molecule defined")
        return True

    residues = project.molecule.residuesWithProperties('protein')
    if not residues:
        nTmessage('runTalosPlus: no amino acids defined')
        return False

    if len( project.molecule.resonanceSources ) == 0:
        nTmessage("==> runTalosPlus: No resonances defined so no sense in running.")
        # JFD: This doesn't catch all cases.
        return False

    talosDefs = project.getStatusDict(constants.TALOSPLUS_KEY, **talosDefaults)

    talosDefs.molecule = project.molecule.asPid
    talosDefs.directory = constants.TALOSPLUS_KEY

    path = project.validationPath( talosDefs.directory )
    if not path:
        return True
    if path.exists():
        nTdebug('runTalosPlus: removing %s with prior data', path)
        path.rmdir()
    path.makedirs()

    startTime = io.now()

    talosDefs.completed = False
    talosDefs.parsed = False
    _resetTalosPlus(project)

    # Exporting the shifts
    fileName = path / talosDefs.tableFile
    if exportShifts2TalosPlus(project, fileName=fileName):
        nTwarning("runTalosPlus: Failed to exportShifts2TalosPlus; this is normal for empty CS list.")
        return False

    # running TalosPlus
    talosProgram = ExecuteProgram(cdefs.cingPaths.talos, rootPath=path, redirectOutput=True)
    nTmessageNoEOL('==> Running talos+ ... ')
    talosProgram( '-in ' + talosDefs.tableFile + ' -sum ' + talosDefs.predFile )
    nTmessage('Done!')

    if _findTalosOutputFiles(path, talosDefs):
        return True

    talosDefs.date = io.now()
    talosDefs.completed=True
    talosDefs.version = __version__
    talosDefs.molecule = project.molecule.asPid
    talosDefs.remark = 'TalosPlus on %s completed in %.1f seconds on %s; data in %s' % \
                       (project.molecule, talosDefs.date-startTime, talosDefs.date, path)

    # Importing the results
    if parseTalosPlus(project):
        nTerror("runTalosPlus: Failed parseTalosPlus")
        return True

    project.history(talosDefs.remark)
    nTmessage('==> %s', talosDefs.remark)
    return False