예제 #1
0
    def getPeakResNames(self):

        self.resNames = []
        self.resLabels = []

        origAssignName = self.rawPeak.assign[self.rawPeakDimIndex]

        if origAssignName not in [None, '?', 'null', '']:

            # Spin systems, not handled although in principle possible.
            if origAssignName.count("{"):
                pass
            else:

                # TODO Problems: No chain code, what if get for example 1CC5 for DNA or RNA? No label separator.
                assignSearch = self.assignPatt.search(origAssignName)

                if assignSearch:
                    if assignSearch.group(1):
                        chainCode = assignSearch.group(1)
                    else:
                        chainCode = defaultMolCode

                    self.resNames.append(
                        getResName(chainCode, assignSearch.group(2),
                                   assignSearch.group(4)))
                    self.resLabels.append(assignSearch.group(3))

                else:
                    print "   No decomposition possible for %s assignment"
예제 #2
0
    def getPeakResNames(self):

        self.resNames = []

        if self.rawPeak.assign:

            # Have to do some interpretation of the assigns...
            assign = self.rawPeak.assign[self.rawPeakDimIndex]

            # Special handling for Montelione group
            if '/' in assign:
                addAssignStrings = assign.split('/')
                assign = addAssignStrings.pop(0)
            else:
                addAssignStrings = []

            if assign != '?':

                # Ignore non-assigned peak dims
                assignString = self.patt[self.format +
                                         'LabelCodeName'].search(assign)

                #
                # In Sparky with K18,19HA-R20HN style assignments multiple resNames
                # are possible here... making list of resNames to accomodate
                #

                if assignString:
                    self.resLabelCodes = assignString.group(1).split(',')
                    atomName = assignString.group(3)

                else:
                    atomName = assign

                for resLabelCode in self.resLabelCodes:
                    self.resNames.append(
                        getResName(defaultMolCode, resLabelCode, atomName))

                # Add any other info (Montelione group again)
                for addAssignString in addAssignStrings:
                    # This should always work in this case
                    assignString = self.patt[
                        self.format + 'LabelCodeName'].search(addAssignString)
                    resName = getResName(defaultMolCode, assignString.group(1),
                                         assignString.group(3))
                    self.resNames.append(resName)
예제 #3
0
    def getSinglePeakResName(self, assignName):

        (residue, atomName) = assignName.split(self.peakFile.assignSep)

        resLabel = residue[0]
        seqCode = returnInt(residue[1:])

        if atomName.count('|'):
            (atomName, otherAtomName) = atomName.split('|')

        self.resNames.append(getResName(defaultMolCode, seqCode, atomName))
예제 #4
0
    def getPeakResNames(self):

        if self.rawPeak.assignResNum[self.rawPeakDimIndex] != '':
            (seqCode, seqInsertCode) = getSeqAndInsertCode(
                self.rawPeak.assignResNum[self.rawPeakDimIndex])
            self.resNames = [
                getResName(' ',
                           seqCode,
                           self.rawPeak.assignAtom[self.rawPeakDimIndex],
                           seqInsertCode=seqInsertCode)
            ]

        else:
            self.resNames = []
예제 #5
0
    def getPeakResNames(self):

        self.resNames = []

        if self.rawPeak.assign[self.rawPeakDimIndex] not in ['-']:

            for assignment in [self.rawPeak.assign
                               ] + self.rawPeak.ambiguousAssign:

                (atomName,
                 seqCode) = assignment[self.rawPeakDimIndex].split('.')

                self.resNames.append(
                    getResName(defaultMolCode, seqCode, atomName))
예제 #6
0
    def getPeakResNames(self):

        self.resNames = []

        if hasattr(self.rawPeak, 'assign'):

            if self.rawPeak.assign[self.rawPeakDimIndex] not in [
                    None, '?', 'null', '', '0'
            ]:

                # TODO is this 'standard' felix type stuff?
                (residueInfo, atomName) = string.split(
                    self.rawPeak.assign[self.rawPeakDimIndex], ':')
                (residueCode, seqCode) = string.split(residueInfo, '_')

                self.resNames.append(
                    getResName(defaultMolCode, seqCode, atomName))
예제 #7
0
    def getSinglePeakResName(self, assignName):

        (seqCode, atomName) = assignName.split(tagSep)
        self.resNames.append(getResName(defaultMolCode, seqCode, atomName))
예제 #8
0
def duplicateResonances(nmrConstraintStore,format,mappingDict):
  
  #
  # Check which resonances have to be copied, and copy...
  #
  
  resonanceMappingDict = {}
  
  copyResonances = []
  resonanceDict = {}

  copyConstraints = []
  constrLinks = ['dihedralConstraints','chemShiftConstraints']

  copyConstraintItems = {}
  copyConstraintItemsList = []
  
  #
  # First determine which resonances are eligible for copying, and create a dictionary with resNames...
  #
  
  for resonance in nmrConstraintStore.sortedFixedResonances():
         
    applData = resonance.findFirstApplicationData(application = format, keyword = assign_kw)

    if applData:

      resName = applData.value
      
      resonanceDict[resName] = resonance

      (chain,seqCode,spinSystemId,seqInsertCode,atomName) = getNameInfo(resName)
              
      if mappingDict.has_key(chain):
        
        copyResonances.append(resonance)
        
  #
  # Then determine which constraint/items have to be copied (all resonances have to have the same chainCode!!)
  #
  
  for resonance in copyResonances:
    
    #
    # Constraints
    #

    for constrLink in constrLinks:
      for constr in getattr(resonance,constrLink):
        copyConstraint = 1
        for otherRes in constr.resonances:
          if otherRes not in copyResonances:
            copyConstraint = 0
            break
        
        if copyConstraint and constr not in copyConstraints:
          j = 0
          constrKey = (constr.parent.serial,constr.serial)
          for j in range(0,):
            if constrKey < (copyConstraints[j].parent.serial,copyConstraints[j].serial):
              copyConstraints.insert(j,constr)
              break
          listLen = len(copyConstraints)
          if j == (listLen - 1) or listLen == 0:
            copyConstraints.append(constr)
            

    #
    # ConstraintItems
    #

    for constrItem in resonance.sortedPairwiseConstraintItems():

      copyConstraintItem = 1
      for otherRes in constrItem.resonances:
        if otherRes not in copyResonances:
          copyConstraintItem = 0
          break

      if copyConstraintItem:
        if not copyConstraintItems.has_key(constrItem.constraint):
          copyConstraintItems[constrItem.constraint] = []
          j = 0

          constrKey = (constrItem.constraint.parent.serial,constrItem.constraint.serial)

          for j in range(0,len(copyConstraintItemsList)):
            if constrKey < (copyConstraintItemsList[j].parent.serial,copyConstraintItemsList[j].serial):
              copyConstraintItemsList.insert(j,constrItem.constraint)
              break
          listLen = len(copyConstraintItemsList)
          #print constrKey, j, listLen
          if j == (listLen - 1) or listLen == 0:
            copyConstraintItemsList.append(constrItem.constraint)

        if constrItem not in copyConstraintItems[constrItem.constraint]:
          copyConstraintItems[constrItem.constraint].append(constrItem)

  #
  # Now copy the resonances or find an existing resonance...
  #
  
  for resonance in copyResonances:
         
    applData = resonance.findFirstApplicationData(application = format, keyword = assign_kw)
    applDataClass = applData.__class__

    resName = applData.value

    (chain,seqCode,spinSystemId,seqInsertCode,atomName) = getNameInfo(resName)
      
    resonanceMappingDict[resonance] = {}
    
    resonance.removeApplicationData(applData)
    
    newValue = getResName(mappingDict[chain][0],seqCode,atomName,seqInsertCode = seqInsertCode)
    resonance.addApplicationData(applDataClass(application = format, keyword = assign_kw, value = newValue))

    for i in range(1,len(mappingDict[chain])):

      newChainCode = mappingDict[chain][i]
      newResName = getResName(newChainCode,seqCode,atomName,seqInsertCode = seqInsertCode)
      
      if resonanceDict.has_key(newResName):
        newResonance = resonanceDict[newResName]
        print "  Using existing resonance %s..." % newResName

      else:

        print "  Creating new resonance %s..." % newResName

        newResonance = nmrConstraintStore.newFixedResonance(isotopeCode = resonance.isotopeCode)
        resonanceDict[newResName] = newResonance

        copyResonanceInfo(resonance,newResonance,toResName = newResName)

        applData = newResonance.findFirstApplicationData(application = format, keyword = assign_kw)
        applDataClass = applData.__class__

        newResonance.removeApplicationData(applData)
        newResonance.addApplicationData(applDataClass(application = format, keyword = assign_kw, value = newResName))

        #
        # Constraints and constraint items have to be deleted and recreated later...
        #
        
        for constrLink in constrLinks:
          for constr in getattr(newResonance,constrLink):
            constr.delete()

        for constrItem in newResonance.pairwiseConstraintItems:
          constrItem.delete()

      resonanceMappingDict[resonance][newChainCode] = newResonance

  #
  # Loop over the 'new' chain codes...
  #
  
  print
  print "########################## "
  print "# Duplicating resonances # "
  print "########################## "
  print
  
  for i in range(1,len(mappingDict[chain])):

    newChainCode = mappingDict[chain][i]
  
    #
    # Copy the relevant dihedral constraints...
    #

    for constraint in copyConstraints:
    
      print "  Copying constraint %d.%d" % (constraint.parent.serial,constraint.serial)
      print "    Resonances %s" % ', '.join([getResNameText(res) for res in constraint.resonances])

      (newResonances, oldToNewResonanceDict) = getMappedResonances(constraint,resonanceMappingDict,newChainCode)
      
      print "            to %s" % ', '.join([getResNameText(res) for res in newResonances])

      newConstr = constraint.__class__(constraint.parent,resonances = newResonances)
      copyAttributeInfo(constraint,newConstr)

      for constrItem in constraint.sortedItems():

        newConstrItem = constrItem.__class__(newConstr, upperLimit = 1.0, lowerLimit = 0.0)
        copyAttributeInfo(constrItem,newConstrItem)
      
      print

    #
    # ..and the constraints from the relevant constraintItems...
    #

    for constraint in copyConstraintItemsList:
   
      print "  Copying constraint %d.%d" % (constraint.parent.serial,constraint.serial)

      newConstr = constraint.__class__(constraint.parent)
      copyAttributeInfo(constraint,newConstr)
      
      if hasattr(constraint,'weight'):
        newConstr.weight = constraint.weight

      for constrItem in constraint.sortedItems():
        print "    Copying item with resonances %s" %  ', '.join([getResNameText(res) for res in constrItem.resonances])
      
        if constrItem in copyConstraintItems[constraint]:

          (newResonances, oldToNewResonanceDict) = getMappedResonances(constrItem,resonanceMappingDict,newChainCode)
        
        else:
        
          newResonances = constrItem.resonances
          oldToNewResonanceDict = {}

      
        print "                              to %s" % ', '.join([getResNameText(res) for res in newResonances])

        newConstrItem = constrItem.__class__(newConstr,resonances = newResonances)

        if constrItem.className in ('DistanceConstraintItem', 'HBondConstraintItem', 'JCouplingConstraintItem', 'RdcConstraintItem'):
          firstResonance = constrItem.firstResonance
          if oldToNewResonanceDict:
            firstResonance = oldToNewResonanceDict[firstResonance] 

          newConstrItem.firstResonance = firstResonance
 
        copyAttributeInfo(constrItem,newConstrItem)
      
      print

  print "###################### "
  print "# End of duplication # "
  print "###################### "
  print
예제 #9
0
    def setRawDistanceConstraintItemMembers(self):

        #
        # Expand the information... is necessary for Concoord (only handles individual atoms)
        #

        atomNameLists = []

        for i in range(0, 2):

            atomNameLists.append([])

            resonanceToAtom = self.ccpInfo[i][3]
            chemAtomOrigName = self.ccpInfo[i][2]

            if resonanceToAtom.chemAtomSet:
                chemAtomOrSet = resonanceToAtom.chemAtomSet
            else:
                chemAtomOrSet = resonanceToAtom.chemAtom

            if chemAtomOrSet:

                chemCompVar = resonanceToAtom.getResidue().chemCompVar
                namingSystem = chemCompVar.chemComp.findFirstNamingSystem(
                    name=self.namingSystemName)
                if namingSystem:
                    chemAtomSysName = findChemAtomSysName(
                        namingSystem, {'sysName': chemAtomOrigName})
                else:
                    chemAtomSysName = None

                if chemAtomSysName:
                    chemAtom = chemCompVar.findFirstChemAtom(
                        name=chemAtomSysName.atomName,
                        subType=chemAtomSysName.atomSubType)
                else:
                    chemAtom = chemCompVar.findFirstChemAtom(
                        name=chemAtomOrigName)

                if not chemAtom:

                    chemAtomSetSysName = findChemAtomSetSysName(
                        namingSystem, {'sysName': chemAtomOrigName})

                    if chemAtomSetSysName:
                        chemAtomSet = chemCompVar.findFirstChemAtomSet(
                            name=chemAtomSetSysName.atomName,
                            subType=chemAtomSetSysName.atomSubType)
                    else:
                        chemAtomSet = chemCompVar.findFirstChemAtomSet(
                            name=chemAtomOrigName)

                    if chemAtomSet:

                        (chainCode, seqCode, spinSystemId, seqInsertCode,
                         atomName) = getNameInfo(self.resSetNames[i])

                        if chemAtomSet.chemAtomSets:
                            chemAtomSets = list(chemAtomSet.chemAtomSets)
                        else:
                            chemAtomSets = [chemAtomSet]

                        for chemAtomSet in chemAtomSets:

                            chemAtomSysNames = self.getChemAtomSysNamesFromSet(
                                chemAtomSet, chemCompVar, findIupac=1)

                            for chemAtomSysName in chemAtomSysNames:

                                if chemAtomSysName:
                                    atomNameLists[-1].append(
                                        getResName(
                                            chainCode,
                                            seqCode,
                                            chemAtomSysName,
                                            seqInsertCode=seqInsertCode))
                                else:
                                    print "  Error: problems with decompressing Concoord name %s - sysNames missing for %s" % (
                                        self.resSetNames[i], chemAtomSet.name)

                    else:
                        print "  Error: can't decompress Concoord name %s" % self.resSetNames[
                            i]

            #
            # If no names use default
            #

            if not atomNameLists[-1]:
                atomNameLists[-1].append(self.resSetNames[i])

        #
        # Now write them one by one...
        #

        itemResonances = getResonancesFromPairwiseConstraintItem(self.item)

        for resSetName0 in atomNameLists[0]:

            # TODO: bit risky this one! What if original names (eg GLU-) are being used?!
            resonance = itemResonances[0]
            resLabel0 = resonance.resonanceSet.findFirstAtomSet(
            ).findFirstAtom().residue.molResidue.chemComp.ccpCode.upper()

            (chainCode0, seqCode0, spinSystemId0, seqInsertCode0,
             atomName0) = getNameInfo(resSetName0)

            if atomName0 == allResidueAtoms_kw:
                print "  Error: not handling residue level constraints for %s." % self.format
                continue

            for resSetName1 in atomNameLists[1]:

                # TODO: bit risky this one! What if original names (eg GLU-) are being used?!
                resonance = itemResonances[1]
                resLabel1 = resonance.resonanceSet.findFirstAtomSet(
                ).findFirstAtom().residue.molResidue.chemComp.ccpCode.upper()

                (chainCode1, seqCode1, spinSystemId1, seqInsertCode1,
                 atomName1) = getNameInfo(resSetName1)

                if atomName1 == allResidueAtoms_kw:
                    print "  Error: not handling residue level constraints for %s." % self.format
                    continue

                #
                # Now set all items and members...
                #

                self.rawConstraint.items.append(self.rawConstraintItemClass())
                self.rawConstraintItem = self.rawConstraint.items[-1]

                self.rawConstraintItem.members.append(
                    self.rawConstraintItemMemberClass())
                self.rawConstraintItem.members[-1].setInfo(
                    chainCode0, seqCode0, resLabel0, atomName0)
                self.rawConstraintItem.members.append(
                    self.rawConstraintItemMemberClass())
                self.rawConstraintItem.members[-1].setInfo(
                    chainCode1, seqCode1, resLabel1, atomName1)