Exemplo n.º 1
0
  def importCnsDistance(self):

    if not self.project:
      showWarning('Failure','Please create a new CCPN project.', parent=self)
      return

    fileTypes = [ FileType('CNS', ['*.tbl']),
                  FileType('All', ['*']) ]

    fileSelectPopup = FileSelectPopup(self, file_types=fileTypes,
                        title='Import CNS distance restraints file', dismiss_text='Cancel',
                        selected_file_must_exist=True, multiSelect=False,)

    fileName = fileSelectPopup.getFile()

    if not os.path.exists(fileName):
      showWarning('Failure','No such file.', parent=self)
      return

    if fileName:
      name = os.path.split(fileName)[1]
      if '.' in name:
        name = name.split('.')[0]

      cnsObj = CnsFormat(self.project, self, verbose=True)
      cnsObj.readDistanceConstraints(fileName, minimalPrompts=True)

      self.eciFrame.updateAll()

      return cnsObj
Exemplo n.º 2
0
def getPdbString(model,
                 chains,
                 chainRename=None,
                 blankchain=False,
                 fileEnd='END'):
    """Description:    Convert a CCPN molEnsemble into a PDB formatted string Atom names will use IUPAC nomenclature
       Input:         MolStructure.StructureEnsemble, list of chains (pdb One Letter Code) to check if we need to 
                    write only a subset of chains of the MolStructure. The chainID can be set to the haddock partner
                    code by using the chainRename argument. If the chain argument is set to True both chain and segid
                    are printed (needed for parameter file).
       Output:         PDB structure String
    """
    project = model.root
    cnsFormat = CnsFormat(project, guiParent=None)

    if chainRename: forceExportSegId = chainRename
    else: forceExportSegId = " "

    if blankchain: forceExportChainId = " "
    else: forceExportChainId = forceExportSegId

    if not chains: chainlist = project.findFirstMolSystem().sortedChains()

    cnsFormat.writeCoordinates('void',
                               structures=[model],
                               forceExportSegId=forceExportSegId,
                               forceExportChainId=forceExportChainId,
                               resetMapping=True,
                               exportChains=chains,
                               minimalPrompts=True,
                               noWrite=True)

    cnsFormat.coordinateFile.write(endStatement=fileEnd, writeString=True)

    return cnsFormat.coordinateFile.coordFileString
Exemplo n.º 3
0
def getCnsObject(project):

    from ccpnmr.format.converters.CnsFormat import CnsFormat

    cnsObj = CnsFormat(project, None, allowPopups=False)

    return cnsObj
Exemplo n.º 4
0
def importXplorCoorAndRes(ccpnProject, inputDir, guiRoot, replaceCoordinates=1, replaceRestraints=1, 
                          allowPopups=1, minimalPrompts=0, verbose=1, **presets):

    if replaceCoordinates:
        status = importPseudoPdb(ccpnProject, inputDir, guiRoot, allowPopups=allowPopups, minimalPrompts=minimalPrompts, 
                                 verbose=verbose, **presets)
        if status:
            nTerror("Failed importXplorCoorAndRes")
            return True

    if not replaceRestraints:
        return

    formatCns = CnsFormat(ccpnProject, guiRoot, verbose=verbose, minimalPrompts=minimalPrompts, allowPopups=allowPopups)
    ccpnConstraintListOfList = []

    # Will overwrite the settings given to formatCns.linkResonances(  below
    globPattern = inputDir + '/*_noe.tbl'
    fileList = glob(globPattern)
    nTdebug("From %s will read files: %s" % (globPattern, fileList))

#    for fn in fileList[0:1]: # TODO:
    for fn in fileList:
        fnBaseName = os.path.basename(fn).split('.')[0]
        ccpnConstraintList = formatCns.readDistanceConstraints(fn, minimalPrompts=minimalPrompts, verbose=verbose)
        ccpnConstraintList.setName(fnBaseName)
        ccpnConstraintListOfList.append(ccpnConstraintList)
        if not ccpnConstraintList:
            nTerror("Failed to read")
            return True

#    globPattern = inputDir + '/*_hbond.tblXXXX' # TODO:
    globPattern = inputDir + '/*_hbond.tbl'
    fileList = glob(globPattern)
    nTdebug("From %s will read in files: %s" % (globPattern, fileList))
    for fn in fileList:
        fnBaseName = os.path.basename(fn).split('.')[0]
        ccpnConstraintList = formatCns.readDistanceConstraints(fn, minimalPrompts=minimalPrompts, verbose=verbose)
        ccpnConstraintList.setName(fnBaseName)
        ccpnConstraintListOfList.append(ccpnConstraintList)

#    globPattern = inputDir + '/*_dihe.tblXXXX' # TODO:
    globPattern = inputDir + '/*_dihe.tbl'
    fileList = glob(globPattern)
    nTdebug("From %s will read in total files: %s" % (globPattern, fileList))
    for fn in fileList:
        fnBaseName = os.path.basename(fn).split('.')[0]
        ccpnConstraintList = formatCns.readDihedralConstraints(fn, minimalPrompts=minimalPrompts, verbose=verbose)
        ccpnConstraintList.setName(fnBaseName)
        ccpnConstraintListOfList.append(ccpnConstraintList)

    keywds = getDeepByKeysOrDefault(presets, {}, LINK_RESONANCES, KEYWORDS)
    nTdebug("From getDeepByKeysOrDefault keywds: %s" % repr(keywds))

    ccpnConstraintList = getDeepByKeys(ccpnConstraintListOfList, 0) # no need to repeat
    nTdebug("First ccpnConstraintList: %s" % ccpnConstraintList)
    if ccpnConstraintList != None:
#    for i, ccpnConstraintList in enumerate(ccpnConstraintListOfList):
        keywds = getDeepByKeysOrDefault(presets, {}, LINK_RESONANCES, KEYWORDS)
        nTdebug("From getDeepByKeysOrDefault keywds: %s" % repr(keywds))
        nTdebug("ccpnConstraintList: %s" % ccpnConstraintList)
        nmrConstraintStore = ccpnConstraintList.nmrConstraintStore
        structureGeneration = nmrConstraintStore.findFirstStructureGeneration()
        formatCns.linkResonances(
                      forceDefaultChainMapping=1, # may be overwritten by using forceChainMappings.
                      globalStereoAssign=1,
                      setSingleProchiral=1,
                      setSinglePossEquiv=1,
                      strucGen=structureGeneration,
                      allowPopups=allowPopups, minimalPrompts=minimalPrompts, verbose=verbose, **keywds)
Exemplo n.º 5
0
    print '\nUrls:'

    for repos in project.sortedRepositories():
        print repos.name, repos.url.path

    print


if __name__ == '__main__':

    # This code follows on from ex7.py.
    project = MemopsRoot(name='constraintsTest')
    guiRoot = Tkinter.Tk()

    cnsObj = CnsFormat(project, guiRoot)

    cnsDir = '../data/cns'

    cnsCoord = 'cns_1.pdb'
    cnsCoordFile = os.path.join(cnsDir, cnsCoord)

    # To make a molSystem object.
    chains = cnsObj.readSequence(cnsCoordFile)

    distConst = 'n15noesy.tbl'
    distConstFile = os.path.join(cnsDir, distConst)

    # To make a structureGeneration object.
    constList = cnsObj.readDistanceConstraints(distConstFile)
Exemplo n.º 6
0
from memops.api.Implementation import MemopsRoot

from ccpnmr.format.converters.CnsFormat import CnsFormat

from ccpnmr.format.general.Util import (createExperiment,
                                        getRefExpFromOldExpType)

from msd.nmrStar.IO.NmrStarExport import NmrStarExport

if __name__ == '__main__':

    # Similar start to code as that found in ex6.py.
    project = MemopsRoot(name='sampleTest')
    guiRoot = Tkinter.Tk()

    cnsObj = CnsFormat(project, guiRoot)

    nmrProject = project.currentNmrProject = \
        project.newNmrProject(name = project.name)
    strucGen = nmrProject.newStructureGeneration()

    cnsDir = '../data/cns'
    cnsFile = os.path.join(cnsDir, 'cns_1.pdb')

    cnsObj.readCoordinates([cnsFile],
                           strucGen=strucGen,
                           minimalPrompts=1,
                           linkAtoms=0)

    # Find molecule made by readCoordinates and set isFinalised to True.
    molecule = project.findFirstMolecule()
Exemplo n.º 7
0
            (oldUrlPath, baseName) = uniIo.splitPath(repository.url.path)
            newUrlPath = uniIo.joinPath(projectDir, baseName)

            repository.url = Implementation.Url(path=newUrlPath)

    #
    # Open a Tk window for handling the popups...
    #

    root = Tkinter.Tk()

    #
    # Create the FormatConverter CnsFormat object
    #

    cnsFormat = CnsFormat(ccpnProject, root)

    #
    # Read in a sequence - this will create the molecular system with
    # all the atom information.
    #
    # Note that a lot of the popups can be avoided when the right information
    # is passed in (see ccpnmr.format.converters.DataFormat, the readSequence
    # function in the DataFormat class)
    #

    coordinateFile = os.path.join(dataDir, coordinateFileName)
    ccpnChains = cnsFormat.readSequence(coordinateFile)

    #
    # Read in a distance constraint list
Exemplo n.º 8
0
            fileDict[strucNum] = file
            strucNumList.append(strucNum)

    strucNumList.sort()

    fileList = []

    for strucNum in strucNumList:

        fileList.append(os.path.join(dataDir, fileDict[strucNum]))

    #
    # Create the format converter CNS format
    #

    cnsFormat = CnsFormat(project, guiRoot, verbose=1)

    #
    # Now read in the structures... this will also create the Molecules and Molecular system via readSequence()
    #

    cnsFormat.readCoordinates(fileList,
                              strucGen=structureGeneration,
                              minimalPrompts=1,
                              linkAtoms=0)

    #
    # Create the format converter PDB format
    #

    pdbFormat = PdbFormat(project, guiRoot, verbose=1)
Exemplo n.º 9
0
      (oldUrlPath,baseName) = uniIo.splitPath(repository.url.path)
      newUrlPath = uniIo.joinPath(projectDir,baseName)

      repository.url = Implementation.Url(path = newUrlPath)

  #
  # Open a Tk window for handling the popups...
  #

  root = Tkinter.Tk()

  #
  # Create the FormatConverter CnsFormat object
  #

  cnsFormat = CnsFormat(ccpnProject,root)

  #
  # Read in a sequence - this will create the molecular system with
  # all the atom information.
  #
  # Note that a lot of the popups can be avoided when the right information
  # is passed in (see ccpnmr.format.converters.DataFormat, the readSequence
  # function in the DataFormat class)
  #

  coordinateFile = os.path.join(dataDir,coordinateFileName)
  ccpnChains = cnsFormat.readSequence(coordinateFile)

  #
  # Read in a distance constraint list
Exemplo n.º 10
0
      fileDict[strucNum] = file
      strucNumList.append(strucNum)

  strucNumList.sort()

  fileList = []

  for strucNum in strucNumList:

    fileList.append(os.path.join(dataDir,fileDict[strucNum]))

  #
  # Create the format converter CNS format
  #

  cnsFormat = CnsFormat(project,guiRoot,verbose = 1)

  #
  # Now read in the structures... this will also create the Molecules and Molecular system via readSequence()
  #

  cnsFormat.readCoordinates(fileList,strucGen = structureGeneration, minimalPrompts = 1, linkAtoms = 0)

  #
  # Create the format converter PDB format
  #

  pdbFormat = PdbFormat(project,guiRoot,verbose = 1)

  #
  # Make sure the outputDir exists...