Пример #1
0
def writeNmrStarFile(entry, nmrStarFileName, nmrStarVersion='3.0'):

    from pdbe.nmrStar.IO.NmrStarExport import NmrStarExport

    nmrStarExport = NmrStarExport(entry, nmrStarVersion=nmrStarVersion)

    nmrStarExport.createFile(nmrStarFileName)
    nmrStarExport.writeFile()
Пример #2
0
    # are part of the BMRB Entry object.
    entry.addStructureGeneration(strucGen)

    # Make a test NOESY experiment.
    refExpType = 'noesy_hsqc_HNH.hhn'
    refExp = getRefExpFromOldExpType(project, refExpType)

    nmrExp = createExperiment(project, 'noesyTest', refExp)
    nmrExp.addMolSystem(molSystem)

    # Link the experiment to the BMRB Entry.
    entry.addExperiment(nmrExp)

    # Save the project to XML files using a sub routine - see above.
    saveProject(project, name='testSave', subDir='../data/cnsOut')

    # Sub routine to print where data for the CCPN project is saved.
    printReposUrls(project)

    curDir = os.path.abspath('../data')
    nmrStarDir = os.path.join(curDir, 'nmrStar')

    if not os.path.exists(nmrStarDir):
        os.mkdir(nmrStarDir)

    outNmrStarFile = os.path.join(nmrStarDir, 'nmrStar4.str')

    nmrStarExport = NmrStarExport(entry, nmrStarVersion='3.1')
    nmrStarExport.createFile(outNmrStarFile)
    nmrStarExport.writeFile()
Пример #3
0
def convert(projectName,
            inputDir,
            outputFile,
            excludeSaveFrames=('general_distance_constraints', )):

    print "projectName: %s" % projectName
    print "inputDir: %s" % inputDir
    print "outputFile: %s" % outputFile
    print "excludeSaveFrames: %s" % excludeSaveFrames
    ccpnPath = os.path.join(inputDir, projectName)
    ccpnProject = loadProject(ccpnPath)

    nmrEntryStore = ccpnProject.newNmrEntryStore(name="newNmrEntryStoreName")
    molSystem = ccpnProject.findFirstMolSystem()
    nmrEntry = nmrEntryStore.newEntry(molSystem=molSystem,
                                      name='newNmrEntryName')

    nmrProject = ccpnProject.currentNmrProject

    nmrEntry.structureGenerations = nmrProject.sortedStructureGenerations()
    if nmrEntry.structureGenerations:
        print "Using structureGenerations from nmrProject"
    else:
        ncs = ccpnProject.findFirstNmrConstraintStore()
        sG = None
        if not ncs:
            print "Failed to find any NmrConstraintStore from project"
        else:
            sG = ncs.findFirstStructureGeneration()
        if sG:
            nmrEntry.addStructureGeneration(sG)
            print "Using structureGenerations from nmrProject"
        else:
            print "Failed to find nmrEntry.structureGenerations from nmrProject or nmrConstraintStore; creating a new one."
            strucGen = nmrProject.newStructureGeneration()
            nmrEntry.addStructureGeneration(strucGen)
        # end if
        # end if
    # end if

    try:  # ccpn stable as 08 Jul 2009
        nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalysiss(
        )  # watch out for misspelling.
    except AttributeError:  # ccpn trunk fixed misspelled function
        nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalyses()
    if not nmrEntry.structureAnalyses:
        print "Failed to find nmrEntry.structureAnalyses"
    nmrEntry.measurementLists = nmrProject.sortedMeasurementLists()
    if not nmrEntry.measurementLists:
        print "Failed to find nmrEntry.measurementLists"

    # Hack to hook up coordinates, hopefully correctly (Wim 30/04/2009)
    if nmrEntry.structureGenerations:
        hasStructureEnsemble = False
        for strucGen in nmrEntry.structureGenerations:
            if strucGen.structureEnsemble:
                hasStructureEnsemble = True
                break
            # end if
        # end for
        print "hasStructureEnsemble: %s" % hasStructureEnsemble
        # This will only work dependably if there is one structureGeneration, one structureEnsemble...
        # Take the one that was created last in any case, fingers crossed that they match up!
        if not hasStructureEnsemble and ccpnProject.structureEnsembles:
            nmrEntry.sortedStructureGenerations(
            )[-1].structureEnsemble = ccpnProject.sortedStructureEnsembles(
            )[-1]
        # end if
    # end if

    for ne in nmrProject.sortedExperiments():  # will be sortedNmrExperiments
        for ds in ne.sortedDataSources():
            for pl in ds.sortedPeakLists():
                nmrEntry.addPeakList(pl)

    nmrStarExport = NmrStarExport(nmrEntry,
                                  nmrStarVersion='3.1',
                                  forceEntryId='1')
    nmrStarExport.createFile(outputFile,
                             excludeSaveFrames=excludeSaveFrames,
                             verbose=True)

    # Set the header comment - only set this if you need a standard header!
    topComment = "# File written for CING by NmrStarExport.py code"
    nmrStarExport.writeFile(title="CING", topComment=topComment, verbose=True)
Пример #4
0
def checkNmrEntryCompleteness(nmrEntry, textReport=False, submissionType='PDB'):

  global starDict
  global ccpn2StarDict
  global ccpnLinkList

  global ccpnObjDict

#  starDict = nmrStarDict.sfDict

  starDict = aditMandDict

  starExport = NmrStarExport(nmrEntry)

  ccpn2Star = Ccpn_To_NmrStar(starExport)
  ccpn2StarDict = ccpn2Star.sfDict

  ccpnLinkList = ccpn2Star.nmrEntryLinkList

  # These are set in ccpnMap/ccpnLoop routines in Ccpn_To_NmrStar

  ccpn2Star.nmrEntry = nmrEntry
  ccpn2Star.authors = list(nmrEntry.authors)

  #print 'DICTS: [%s] [%s]' % (starDict, ccpn2StarDict)
 
  ccpnObjDict = checkCcpnObjects(nmrEntry, submissionType)

  setCcpnVar(nmrEntry)

  #print 'CCPN OBJ DICT: [%s]' % ccpnObjDict

  finalInfoDict = {}

  redColour    = '#FF4040'
  orangeColour = '#E0B040'
  yellowColour = '#F0F020'
  greenColour  = '#B0FFB0'

  for ccpnObj in ccpnObjDict.keys():
    #print 'OBJ: [%s] [%s]' % (ccpnObj, ccpnObjDict[ccpnObj])

    if ccpnObj == 'otherCitations':
      continue

    if ccpnObj == 'structureGenerations' and submissionType == 'BMRB':
      continue

    if not ccpnObjDict[ccpnObj][0]:
      #print 'MISSING OBJ: [%s]' % ccpnObj
      finalInfoDict[ccpnObj] = (ccpnObjDict[ccpnObj][1], 'No "' + ccpnObjDict[ccpnObj][2] + '" set/selected', redColour, False, 'Object', 0, ccpnObj, None, None)
    else:
      #print 'PRESENT OBJ: [%s]' % ccpnObj
      finalInfoDict[ccpnObj] = (ccpnObjDict[ccpnObj][1], '"' + ccpnObjDict[ccpnObj][2] + '" done', greenColour, True, 'Object', 3, ccpnObj, None, None)


  # TODO list:

  # CCPN objects not in NMR-STAR
  #'entryMolecules',

  # CCPN objects that are not mandatory for NMR depositions - but required for structure depositions
  #'structureEnsemble',
  #'structureGenerations',
  # Constraint objects

  # NMR-STAR SF's/tables to be done - These aren't objects in CCPN - but are attributes.
  #'SG_project', 'Struct_keywords',
  #'Vendor', 'Task',


  # Rough translation of NmrStar save frames/tables to CCPN objects.

  starSf2CcpnDict = {'entry_information':        'nmrEntry',
                     'citations':                'primaryCitation', # 'otherCitations',
                     'assembly':                 'molSystem',
                     'entity':                   'molecule',
                     'natural_source':           'naturalSource',
                     'experimental_source':      'experimentalSource',
                     'sample':                   'sample',
                     'sample_conditions':        'sampleConditionSet',
                     'software':                 'software',
                     'NMR_spectrometer_list':    'spectrometer',
                     'experiment_list':          'experiments',
                     'assigned_chemical_shifts': 'shiftLists',
                     'chem_shift_reference':     'shiftReferences'}

  starTable2CcpnDict = {'Contact_person':            'contactPersons', # 'personInGroups',
                        'Entry_author':              'authors',
                        #'SG_project':                None,
                        #'Struct_keywords':           'keywords',
                        'Citation_author':           'citationAuthors',
                        'Entity_assembly':           'chains',
                        'Entity_natural_src':        'naturalSource',
                        'Entity_experimental_src':   'experimentalSource',
                        'Sample_component':          'sampleComponent',
                        'Sample_condition_variable': 'sampleConditions',
                        #'Vendor':                    'software',
                        #'Task':                      'software',
                        'NMR_spectrometer_view':     'spectrometer',
                        'Experiment':                'experiments',
                        'Chem_shift_experiment':     'shiftExperiments',
                        'Atom_chem_shift':           'shifts',
                        'Chem_shift_ref':            'shiftReferences'}

  # Mandatory save frames/tables in NmrStar (ADIT-NMR).

  # TODO: Eldon's ADIT-NMR dictionary doesn't include chem shift references,
  #   chem shift lists and structural (PDB) data.

  mandSfList = ['entry_information',
                'citations',
                'assembly',
                'entity',
                'natural_source',
                'experimental_source',
                'sample',
                'sample_conditions',
                'software',
                'NMR_spectrometer_list',
                'experiment_list',
                'chem_shift_reference',
                'assigned_chemical_shifts']

  mandTableDict = {'entry_information':        ['Contact_person',
                                                'Entry_author',
                                                'SG_project',
                                                'Struct_keywords'],
                   'citations':                ['Citation_author'],
                   'assembly':                 ['Entity_assembly'],
                   'entity':                   [],
                   'natural_source':           ['Entity_natural_src'],
                   'experimental_source':      ['Entity_experimental_src'],
                   'sample':                   ['Sample_component'],
                   'sample_conditions':        ['Sample_condition_variable'],
                   'software':                 ['Vendor',
                                                'Task'],
                   'NMR_spectrometer_list':    ['NMR_spectrometer_view'],
                   'experiment_list':          ['Experiment'],
                   'chem_shift_reference':     ['Chem_shift_ref'],
                   'assigned_chemical_shifts': ['Chem_shift_experiment',
                                                'Atom_chem_shift']}

  # These two dictionaries store the CCPN data.

  global sfCcpnMapDict
  global tableCcpnMapDict

  sfCcpnMapDict = {}
  tableCcpnMapDict = {}

  sfTagDict = {}

  for sfKey in nmrStarDict.sfList:
    if sfKey not in mandSfList:
      continue

    if sfKey in starSf2CcpnDict:
      ccpnObj = starSf2CcpnDict[sfKey]

      #print 'SF KEY: [%s] [%s] [%s]' % (sfKey, ccpnObj, ccpnObjDict[ccpnObj])

      # If no CCPN object, then we don't need to check for missing attributes.
      # Need to tell people to make a new CCPN object first.

      if ccpnObj in ccpnObjDict and not ccpnObjDict[ccpnObj][0]:
        #print 'NO SF CCPN OBJ: [%s] [%s]' % (sfKey, ccpnObj)
        continue

    sfTagDict = checkSfTags(sfKey)
    sfMappingDict = checkMappingSfTags(sfTagDict)

    # TODO: add me
    #print 'MAPPING SF DICT: [%s] [%s]' % (sfKey, sfMappingDict)

    if sfKey not in starDict or not 'tableNames' in starDict[sfKey]:
      continue

    for tableName in starDict[sfKey]['tableNames']:
      if tableName not in mandTableDict[sfKey]:
        continue

      if tableName in starTable2CcpnDict:
        ccpnObj = starTable2CcpnDict[tableName]

        #print 'TABLE KEY: [%s] [%s] [%s] [%s]' % (sfKey, tableName, ccpnObj, ccpnObjDict[ccpnObj])

        # Again if no CCPN object...

        if ccpnObj in ccpnObjDict and not ccpnObjDict[ccpnObj][0]:
          if ccpnObj == 'contactPersons':
            if 'personInGroups' in ccpnObjDict and not ccpnObjDict['personInGroups'][0]:
              #print 'NO TABLE CCPN OBJ: [%s] [%s/personInGroups]' % (sfKey, tableName, ccpnObj)
              continue
          else:
            #print 'NO TABLE CCPN OBJ: [%s] [%s]' % (sfKey, tableName, ccpnObj)
            continue

      tableTagDict = checkTableTags(sfKey, tableName)
      tableMappingDict = checkMappingTableTags(tableTagDict)

      # TODO: add me
      #print 'MAPPING TABLE DICT: [%s] [%s] [%s]' % (sfKey, tableName, tableMappingDict)

  for sfKey in sfCcpnMapDict:
    for tagName in sfCcpnMapDict[sfKey]:
      ccpnData = sfCcpnMapDict[sfKey][tagName]
      starInfo = starDict[sfKey]['tags'][tagName][3].strip()

      #print 'SF DATA: [%s] [%s] [%s] [%s]' % (sfKey, tagName, ccpnData, starInfo)

      emptyFlag = True

      if None in ccpnData:
        ccpnData.remove(None)
      elif '' in ccpnData:
        ccpnData.remove('')
      else:
        emptyFlag = False

      if not ccpnData:
        finalInfoDict[sfKey + '_' + tagName] = (STAR_TO_CCPN_SF_NAMES[sfKey] + ' [' + tagName + ']', 'No "' + starInfo + '" attribute set/selected', orangeColour, False, 'SF Attr', 1, sfKey, None, tagName)
      elif emptyFlag:
        finalInfoDict[sfKey + '_' + tagName] = (STAR_TO_CCPN_SF_NAMES[sfKey] + ' [' + tagName + ']', 'Some "' + starInfo + '" attributes not set/selected', yellowColour, False, 'SF Attr', 2, sfKey, None, tagName)
      #else:
      #  finalInfoDict[sfKey + '_' + tagName] = (sfKey + ': ' + tagName, starInfo + ' attribute set/selected', greenColour, True, 'SF Attr')

  for sfKey in tableCcpnMapDict:
    for tableName in tableCcpnMapDict[sfKey]:
      for tagName in tableCcpnMapDict[sfKey][tableName]:
        ccpnData = tableCcpnMapDict[sfKey][tableName][tagName]
        starInfo = starDict[sfKey]['tables'][tableName]['tags'][tagName][3].strip()

        #print 'TABLE DATA1: [%s] [%s] [%s] [%s] [%s]' % (sfKey, tableName, tagName, ccpnData, starInfo)

        emptyFlag = True

        if None in ccpnData:
          ccpnData.remove(None)
        elif '' in ccpnData:
          ccpnData.remove('')
        else:
          emptyFlag = False

        if not ccpnData:
          finalInfoDict[sfKey + '_' + tableName + '_' + tagName] = (STAR_TO_CCPN_TABLE_NAMES[tableName] + ' [' + tagName + ']', 'No "' + starInfo + '" attribute set/selected', orangeColour, False, 'Table Attr', 1, sfKey, tableName, tagName)
        elif emptyFlag:
          finalInfoDict[sfKey + '_' + tableName + '_' + tagName] = (STAR_TO_CCPN_TABLE_NAMES[tableName] + ' [' + tagName + ']', 'Some "' + starInfo + '" attributes not set/selected', yellowColour, False, 'Table Attr', 2, sfKey, tableName, tagName)
        #else:
        #  finalInfoDict[sfKey + '_' + tableName + '_' + tagName] = (sfKey + '/' + tableName + ': ' + tagName, starInfo + ' attribute set/selected', greenColour, True, 'Table Attr')

  finalInfoList = []

  for key in sorted(finalInfoDict.keys() ):
    finalInfoList.append(finalInfoDict[key])

  finalInfoList.sort(listCol6Cmp)

  if not textReport:
    finalInfoList2 = []

    for row in finalInfoList:
      finalInfoList2.append(row[:3])

    return finalInfoList2

  else:
    finalInfoList3 = []

    for row in finalInfoList:
      finalInfoList3.append(row)

    return finalInfoList3
Пример #5
0
def convert(projectName,
            inputDir,
            outputFile,
            excludeSaveFrames=('general_distance_constraints', )):

    print "projectName: %s" % projectName
    print "inputDir: %s" % inputDir
    print "outputFile: %s" % outputFile
    print "excludeSaveFrames: %s" % excludeSaveFrames
    ccpnPath = os.path.join(inputDir, projectName)
    ccpnProject = loadProject(ccpnPath)

    # Try to find the CING setup info in the project.
    cingCalcStore = ccpnProject.findFirstNmrCalcStore(name='CING')
    if cingCalcStore is not None:
        nmrProject = cingCalcStore.nmrProject

        run = cingCalcStore.findFirstRun(status='pending')
        nmrConstraintStore = run.findFirstData(
            className='ConstraintStoreData').nmrConstraintStore
        molSystem = (
            run.findFirstData(className='MolSystemData') or run.findFirstData(
                className='StructureEnsembleData').structureEnsemble
            or run.findFirstData(
                className='MolResidueData').findFirstChain()).molSystem
        nmrEntryStore = (
            ccpnProject.findFirstNmrEntryStore(name='newNmrEntryStoreName')
            or ccpnProject.newNmrEntryStore(name='newNmrEntryStoreName'))

        nmrEntry = nmrEntryStore.newEntry(molSystem=molSystem,
                                          name='newNmrEntryName')
        structureGeneration = nmrProject.newStructureGeneration(
            name='newNmrStructureGeneration',
            nmrConstraintStore=nmrConstraintStore)
        nmrEntry.addStructureGeneration(structureGeneration)

        nmrEntry.measurementLists = [
            x.measurementList
            for x in run.findAllData(className='MeasurementListData')
        ]
        nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalyses()
        nmrEntry.peakLists = [
            x.peakList for x in run.findAllData(className='PeakListData')
        ]

        structureGeneration.structureEnsemble = run.findFirstData(
            className='StructureEnsembleData').structureEnsemble
    else:
        nmrEntryStore = ccpnProject.newNmrEntryStore(
            name="newNmrEntryStoreName")
        molSystem = ccpnProject.findFirstMolSystem()
        nmrEntry = nmrEntryStore.newEntry(molSystem=molSystem,
                                          name='newNmrEntryName')

        nmrProject = ccpnProject.currentNmrProject
        #
        # nmrEntry.structureGenerations = nmrProject.sortedStructureGenerations()
        # if nmrEntry.structureGenerations:
        #     print "Using structureGenerations from nmrProject"
        structureGenerations = nmrProject.sortedStructureGenerations()

        if structureGenerations:
            # NBNB RHF October 2014. WATTOS breaks if there is more than one structureGeneration
            # Add the newest ony, and let the pre-existing code take care of ensembles
            nmrEntry.addStructureGeneration(structureGenerations[-1])
        else:
            ncs = ccpnProject.findFirstNmrConstraintStore()
            sG = None
            if not ncs:
                print "Failed to find any NmrConstraintStore from project"
            else:
                sG = ncs.findFirstStructureGeneration()
            if sG:
                nmrEntry.addStructureGeneration(sG)
                print "Using structureGenerations from nmrProject"
            else:
                print "Failed to find nmrEntry.structureGenerations from nmrProject or nmrConstraintStore; creating a new one."
                strucGen = nmrProject.newStructureGeneration()
                nmrEntry.addStructureGeneration(strucGen)
            # end if
            # end if
        # end if

        try:  # ccpn stable as 08 Jul 2009
            nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalysiss(
            )  # watch out for misspelling.
        except AttributeError:  # ccpn trunk fixed misspelled function
            nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalyses()
        if not nmrEntry.structureAnalyses:
            print "Failed to find nmrEntry.structureAnalyses"
        nmrEntry.measurementLists = nmrProject.sortedMeasurementLists()
        if not nmrEntry.measurementLists:
            print "Failed to find nmrEntry.measurementLists"

        # TJR, RHF 16 Oct 2014
        # DIfferent hack. We now have only ever allow 1 (ONE) structureGeneration.
        assert len(nmrEntry.root.sortedStructureEnsembles()
                   ) == 1, "Must have one and only one ensemble"
        assert len(nmrProject.sortedNmrConstraintStores()
                   ) == 1, "Must have one and only one set of constraints"

        #
        #  Hack to hook up coordinates, hopefully correctly (Wim 30/04/2009)
        #    if nmrEntry.structureGenerations:
        #       hasStructureEnsemble = False
        #       for strucGen in nmrEntry.structureGenerations:
        #           if strucGen.structureEnsemble:
        #               hasStructureEnsemble = True
        #               break
        #           # end if
        #       # end for
        #
        #       print "hasStructureEnsemble: %s" % hasStructureEnsemble
        #       # This will only work dependably if there is one structureGeneration, one structureEnsemble...
        #       # Take the one that was created last in any case, fingers crossed that they match up!
        #       if not hasStructureEnsemble and ccpnProject.structureEnsembles:
        #           nmrEntry.sortedStructureGenerations()[-1].structureEnsemble = ccpnProject.sortedStructureEnsembles()[-1]
        #       # end if
        #    # end if

        for ne in nmrProject.sortedExperiments(
        ):  # will be sortedNmrExperiments
            for ds in ne.sortedDataSources():
                for pl in ds.sortedPeakLists():
                    nmrEntry.addPeakList(pl)

    nmrStarExport = NmrStarExport(nmrEntry,
                                  nmrStarVersion='3.1',
                                  forceEntryId='1')
    nmrStarExport.createFile(outputFile,
                             excludeSaveFrames=excludeSaveFrames,
                             verbose=True)

    # Set the header comment - only set this if you need a standard header!
    topComment = "# File written for CING by NmrStarExport.py code"
    nmrStarExport.writeFile(title="CING", topComment=topComment, verbose=True)
Пример #6
0
def convert(projectName, inputDir, outputFile, excludeSaveFrames = ('general_distance_constraints',) ):

    print "projectName: %s" % projectName
    print "inputDir: %s" % inputDir
    print "outputFile: %s" % outputFile
    print "excludeSaveFrames: %s" % excludeSaveFrames
    ccpnPath = os.path.join(inputDir, projectName)
    ccpnProject = loadProject(ccpnPath)

    # Try to find the CING setup info in the project.
    cingCalcStore = ccpnProject.findFirstNmrCalcStore(name='CING')
    if cingCalcStore is not None:
        nmrProject = cingCalcStore.nmrProject

        run = cingCalcStore.findFirstRun(status='pending')
        nmrConstraintStore = run.findFirstData(className='ConstraintStoreData').nmrConstraintStore
        molSystem = (run.findFirstData(className='MolSystemData') or
                     run.findFirstData(className='StructureEnsembleData').structureEnsemble or
                     run.findFirstData(className='MolResidueData').findFirstChain()).molSystem
        nmrEntryStore = (ccpnProject.findFirstNmrEntryStore(name='newNmrEntryStoreName') or
                               ccpnProject.newNmrEntryStore(name='newNmrEntryStoreName'))

        nmrEntry = nmrEntryStore.newEntry(molSystem=molSystem, name='newNmrEntryName')
        structureGeneration = nmrProject.newStructureGeneration(name='newNmrStructureGeneration',
                                                                nmrConstraintStore=nmrConstraintStore)
        nmrEntry.addStructureGeneration(structureGeneration)

        nmrEntry.measurementLists = [x.measurementList for x in run.findAllData(className='MeasurementListData')]
        nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalyses()
        nmrEntry.peakLists = [x.peakList for x in run.findAllData(className='PeakListData')]

        structureGeneration.structureEnsemble = run.findFirstData(className='StructureEnsembleData').structureEnsemble
    else:
        nmrEntryStore = ccpnProject.newNmrEntryStore(name = "newNmrEntryStoreName")
        molSystem = ccpnProject.findFirstMolSystem()
        nmrEntry = nmrEntryStore.newEntry( molSystem = molSystem, name = 'newNmrEntryName')

        nmrProject = ccpnProject.currentNmrProject
        #
        # nmrEntry.structureGenerations = nmrProject.sortedStructureGenerations()
        # if nmrEntry.structureGenerations:
        #     print "Using structureGenerations from nmrProject"
        structureGenerations = nmrProject.sortedStructureGenerations()

        if structureGenerations:
            # NBNB RHF October 2014. WATTOS breaks if there is more than one structureGeneration
            # Add the newest ony, and let the pre-existing code take care of ensembles
            nmrEntry.addStructureGeneration(structureGenerations[-1])
        else:
           ncs = ccpnProject.findFirstNmrConstraintStore()
           sG = None
           if not ncs:
               print "Failed to find any NmrConstraintStore from project"
           else:
               sG = ncs.findFirstStructureGeneration()
           if sG:
               nmrEntry.addStructureGeneration( sG )
               print "Using structureGenerations from nmrProject"
           else:
               print "Failed to find nmrEntry.structureGenerations from nmrProject or nmrConstraintStore; creating a new one."
               strucGen = nmrProject.newStructureGeneration()
               nmrEntry.addStructureGeneration(strucGen)
           # end if
           # end if
        # end if

        try: # ccpn stable as 08 Jul 2009
           nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalysiss() # watch out for misspelling.
        except AttributeError: # ccpn trunk fixed misspelled function
           nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalyses()
        if not nmrEntry.structureAnalyses:
           print "Failed to find nmrEntry.structureAnalyses"
        nmrEntry.measurementLists = nmrProject.sortedMeasurementLists()
        if not nmrEntry.measurementLists:
           print "Failed to find nmrEntry.measurementLists"


        # TJR, RHF 16 Oct 2014
        # DIfferent hack. We now have only ever allow 1 (ONE) structureGeneration.
        assert len(nmrEntry.root.sortedStructureEnsembles()) == 1, "Must have one and only one ensemble"
        assert len(nmrProject.sortedNmrConstraintStores()) == 1, "Must have one and only one set of constraints"

        #
        #  Hack to hook up coordinates, hopefully correctly (Wim 30/04/2009)
        #    if nmrEntry.structureGenerations:
        #       hasStructureEnsemble = False
        #       for strucGen in nmrEntry.structureGenerations:
        #           if strucGen.structureEnsemble:
        #               hasStructureEnsemble = True
        #               break
        #           # end if
        #       # end for
        #
        #       print "hasStructureEnsemble: %s" % hasStructureEnsemble
        #       # This will only work dependably if there is one structureGeneration, one structureEnsemble...
        #       # Take the one that was created last in any case, fingers crossed that they match up!
        #       if not hasStructureEnsemble and ccpnProject.structureEnsembles:
        #           nmrEntry.sortedStructureGenerations()[-1].structureEnsemble = ccpnProject.sortedStructureEnsembles()[-1]
        #       # end if
        #    # end if

        for ne in nmrProject.sortedExperiments(): # will be sortedNmrExperiments
           for ds in ne.sortedDataSources():
               for pl in ds.sortedPeakLists():
                   nmrEntry.addPeakList(pl)

    nmrStarExport = NmrStarExport(nmrEntry, nmrStarVersion = '3.1', forceEntryId = '1')
    nmrStarExport.createFile(outputFile, excludeSaveFrames= excludeSaveFrames, verbose = True)

    # Set the header comment - only set this if you need a standard header!
    topComment = "# File written for CING by NmrStarExport.py code"
    nmrStarExport.writeFile(title = "CING", topComment=topComment, verbose = True)
Пример #7
0
def convert(projectName, inputDir, outputFile, excludeSaveFrames=("general_distance_constraints",)):

    print "projectName: %s" % projectName
    print "inputDir: %s" % inputDir
    print "outputFile: %s" % outputFile
    print "excludeSaveFrames: %s" % excludeSaveFrames
    ccpnPath = os.path.join(inputDir, projectName)
    ccpnProject = loadProject(ccpnPath)

    nmrEntryStore = ccpnProject.newNmrEntryStore(name="newNmrEntryStoreName")
    molSystem = ccpnProject.findFirstMolSystem()
    nmrEntry = nmrEntryStore.newEntry(molSystem=molSystem, name="newNmrEntryName")

    nmrProject = ccpnProject.currentNmrProject

    nmrEntry.structureGenerations = nmrProject.sortedStructureGenerations()
    if nmrEntry.structureGenerations:
        print "Using structureGenerations from nmrProject"
    else:
        ncs = ccpnProject.findFirstNmrConstraintStore()
        sG = None
        if not ncs:
            print "Failed to find any NmrConstraintStore from project"
        else:
            sG = ncs.findFirstStructureGeneration()
        if sG:
            nmrEntry.addStructureGeneration(sG)
            print "Using structureGenerations from nmrProject"
        else:
            print "Failed to find nmrEntry.structureGenerations from nmrProject or nmrConstraintStore; creating a new one."
            strucGen = nmrProject.newStructureGeneration()
            nmrEntry.addStructureGeneration(strucGen)
        # end if
        # end if
    # end if

    try:  # ccpn stable as 08 Jul 2009
        nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalysiss()  # watch out for misspelling.
    except AttributeError:  # ccpn trunk fixed misspelled function
        nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalyses()
    if not nmrEntry.structureAnalyses:
        print "Failed to find nmrEntry.structureAnalyses"
    nmrEntry.measurementLists = nmrProject.sortedMeasurementLists()
    if not nmrEntry.measurementLists:
        print "Failed to find nmrEntry.measurementLists"

    # Hack to hook up coordinates, hopefully correctly (Wim 30/04/2009)
    if nmrEntry.structureGenerations:
        hasStructureEnsemble = False
        for strucGen in nmrEntry.structureGenerations:
            if strucGen.structureEnsemble:
                hasStructureEnsemble = True
                break
            # end if
        # end for
        print "hasStructureEnsemble: %s" % hasStructureEnsemble
        # This will only work dependably if there is one structureGeneration, one structureEnsemble...
        # Take the one that was created last in any case, fingers crossed that they match up!
        if not hasStructureEnsemble and ccpnProject.structureEnsembles:
            nmrEntry.sortedStructureGenerations()[-1].structureEnsemble = ccpnProject.sortedStructureEnsembles()[-1]
        # end if
    # end if

    for ne in nmrProject.sortedExperiments():  # will be sortedNmrExperiments
        for ds in ne.sortedDataSources():
            for pl in ds.sortedPeakLists():
                nmrEntry.addPeakList(pl)

    nmrStarExport = NmrStarExport(nmrEntry, nmrStarVersion="3.1", forceEntryId="1")
    nmrStarExport.createFile(outputFile, excludeSaveFrames=excludeSaveFrames, verbose=True)

    # Set the header comment - only set this if you need a standard header!
    topComment = "# File written for CING by NmrStarExport.py code"
    nmrStarExport.writeFile(title="CING", topComment=topComment, verbose=True)