def get_bound_resonances_of_isotope(resonance, isotope): '''For a resonance, get all resonances of an isotope type bound to this resonance. ''' isotopeCode = '{}{}'.format(isotope.massNumber, isotope.chemElement.symbol) # Use getBoundResonance to get from e.g. Cga to Hga* and not Hgb* resonancesA = set(x for x in getBoundResonances(resonance, recalculate=True) if x.isotopeCode == isotopeCode and x.resonanceSet) # get covalently bound atomSts atoms = set() for atomSet in resonance.resonanceSet.atomSets: atoms.update(getBoundAtoms(atomSet.findFirstAtom())) atomSets = set(a.atomSet for a in atoms if a.atomSet and \ a.chemAtom.chemElement is isotope.chemElement) if resonancesA: # remove covalently impossible resonances resonanceSets = set(y for x in atomSets for y in x.resonanceSets) resonancesA = set(x for x in resonancesA if x.resonanceSet in resonanceSets) if not resonancesA: nmrProject = resonance.parent # make new resonances for covanlently bound atoms for atomSet in atomSets: resonanceB = nmrProject.newResonance(isotopeCode=isotopeCode) assignAtomsToRes([atomSet,], resonanceB) resonancesA.add(resonanceB) return resonancesA
def shiftx(structure, atomType=None): from ccpnmr.analysis.core.StructureBasic import makePdbFromStructure from ccpnmr.analysis.core.MoleculeBasic import makeResidueAtomSets, DEFAULT_ISOTOPES from ccpnmr.analysis.core.AssignmentBasic import assignAtomsToRes memopsRoot = structure.root nmrProject = memopsRoot.currentNmrProject dataRepository = memopsRoot.findFirstRepository(name='userData') projPath = dataRepository.url.dataLocation tempDir = path.join(projPath, 'shiftx') if not path.exists(tempDir): mkdir(tempDir) pdbFile = path.join(tempDir, 'shiftxInput.pdb') outFile = path.join(tempDir, 'shiftxOutput.out') exeFile = path.join(SHIFTX_DIR, 'shiftx') chainDict = {} shiftList = None for model in structure.models: makePdbFromStructure(pdbFile, structure, model=model, useOxt=True) for coordChain in structure.sortedCoordChains(): chain = coordChain.chain print 'CCPN SHIFTX executing for chain %s' % chain.code cmd = '%s 1%s %s %s' % (exeFile, chain.code, pdbFile, outFile) system(cmd) fileHandle = open(outFile, 'r') lines = fileHandle.readlines() if chain not in chainDict: chainDict[chain] = shiftData = {} else: shiftData = chainDict[chain] for line in lines: data = line.split() if not data: continue first = data[0] if first.upper() == 'NUM': atomNames = data[2:] elif first[0] == '-': continue elif first[0] == '*': continue elif first.isdigit(): # What to do with alt codes and inaccuracies? *10, 12A etc seqCode = int(first) resCode = data[1] if seqCode not in shiftData: shiftData[seqCode] = shiftDict = {} else: shiftDict = shiftData[seqCode] for i, atomName in enumerate(atomNames): if atomName not in shiftDict: shiftDict[atomName] = [] shiftDict[atomName].append(float(data[i+2])) for chain in chainDict: print 'CCPN SHIFTX filling shift list for chain %s' % chain.code shiftData = chainDict[chain] if shiftData: if not shiftList: msCode = structure.molSystem.code eId = structure.ensembleId details = 'SHIFTX prediction for %s ensemble %d' % (msCode, eId) shiftList = nmrProject.newShiftList(name='SHIFTX', details=details, isSimulated=True) for residue in chain.sortedResidues(): shiftDict = shiftData.get(residue.seqCode) if not shiftDict: continue getAtom = residue.findFirstAtom for atomName in shiftDict: atom = getAtom(name=atomName) if not atom: # Gly HA -> HA2, Ala HB - HB2, Val HG1 - HG12 atom = getAtom(name=atomName+'2') if not atom: continue ppms = shiftDict[atomName] ppm = sum(ppms)/float(len(ppms)) if ppm == 0.0: # Could actually be a real value... continue atomSet = atom.atomSet if not atomSet: makeResidueAtomSets(residue) atomSet = atom.atomSet resonance = None for resonanceSet in atomSet.resonanceSets: resonances = list(resonanceSet.resonances) if len(resonances) == 1: resonance = resonances[0] if not resonance: isotopeCode = DEFAULT_ISOTOPES[atom.chemAtom.chemElement.symbol] resonance = nmrProject.newResonance(isotopeCode=isotopeCode) assignAtomsToRes([atomSet,], resonance) if shiftList.findFirstMeasurement(resonance=resonance): print residue.seqCode, residue.ccpCode, atom.name else: shift = shiftList.newShift(value=ppm, resonance=resonance) print 'CCPN SHIFTX done' return shiftList
def makeResidueAtomSetsEquivalent(residue): """Remake a residue's atom sets if they are found to be equivalent: e.g. if an aromatic ring rotates quickly on the NMR timescale .. describe:: Input MolSystem.Residue .. describe:: Output None """ #chain = residue.chain molType = residue.molResidue.molType residueMapping = getResidueMapping(residue) equivalent = {} elementSymbolDict = {} chemAtomSetDict = {} for atom in residue.atoms: chemAtom = atom.chemAtom chemAtomSetDict[atom] = chemAtom elementSymbol = chemAtom.elementSymbol if chemAtom.chemAtomSet: chemAtomSet = chemAtom.chemAtomSet name = chemAtomSet.name if chemAtomSet.isEquivalent is None: # i.e. not False, aromatic rotation if equivalent.get(name) is None: equivalent[name] = [] equivalent[name].append(atom) elementSymbolDict[name] = chemAtom.elementSymbol chemAtomSetDict[name] = chemAtomSet for groupName in equivalent.keys(): atoms = equivalent[groupName] if atoms[0].atomSet: for atom in atoms[1:]: if atom.atomSet is atoms[0].atomSet: return elementSymbol = elementSymbolDict[groupName] chemAtomSet = chemAtomSetDict[groupName] resonances = [] for atom in atoms: # TBD more nested layers? # delete ambiguous name = makeGuiName(chemAtomSet.name, elementSymbol, molType) atomSetMapping = residueMapping.findFirstAtomSetMapping(name=name) if atomSetMapping: atomSetMapping.delete() # delete stereospecific name = makeGuiName(atom.chemAtom.name, elementSymbol, molType) atomSetMapping = residueMapping.findFirstAtomSetMapping(name=name) if atomSetMapping: atomSetMapping.delete() # delete non-stereospecific name = makeGuiName(makeNonStereoName(molType, atom.chemAtom.name), elementSymbol, molType) atomSetMapping = residueMapping.findFirstAtomSetMapping(name=name) if atomSetMapping: atomSetMapping.delete() atomSet = atom.atomSet if atomSet: for resonanceSet in atomSet.resonanceSets: resonances.extend(resonanceSet.resonances) atomSet.delete() elementSymbol = elementSymbolDict[groupName] chemAtomSet = chemAtomSetDict[groupName] # make single equivalent group #makeAtomSet(,groupName,atoms,chemAtomSet,'simple') atomSet = makeAtomSet(groupName, atoms, chemAtomSet, 'simple') for resonance in resonances: assignAtomsToRes([ atomSet, ], resonance)
def makeResidueAtomSetsNonEquivalent(residue): """Remake a residue's atom sets if they are found to be non-equivalent: e.g. if an aromatic ring does not rotate quickly on the NMR timescale .. describe:: Input MolSystem.Residue .. describe:: Output None """ residueMapping = getResidueMapping(residue) #chain = residue.chain molType = residue.molResidue.molType nonequivalent = {} elementSymbolDict = {} chemAtomSetDict = {} for atom in residue.atoms: chemAtom = atom.chemAtom chemAtomSetDict[atom] = chemAtom elementSymbol = chemAtom.elementSymbol if chemAtom.chemAtomSet: chemAtomSet = chemAtom.chemAtomSet name = chemAtomSet.name if chemAtomSet.isEquivalent is None: # i.e. not False, aromatic rotation if nonequivalent.get(name) is None: nonequivalent[name] = [] nonequivalent[name].append(atom) elementSymbolDict[name] = chemAtom.elementSymbol chemAtomSetDict[name] = chemAtomSet for groupName in nonequivalent.keys(): atoms = nonequivalent[groupName] atomSet = atoms[0].atomSet if atomSet: for atom in atoms[1:]: if atom.atomSet is not atoms[0].atomSet: return # already seperate elementSymbol = elementSymbolDict[groupName] chemAtomSet = chemAtomSetDict[groupName] resonances = [] if atomSet: for resonanceSet in atomSet.resonanceSets: for resonance in resonanceSet.resonances: resonances.append(resonance) atomSet.delete() name = makeGuiName(groupName, elementSymbol, molType) atomSetMapping = residueMapping.findFirstAtomSetMapping(name=name) if atomSetMapping: atomSetMapping.delete() atomSets = [] atomSetNames = [] for atom in atoms: name = chemAtomSetDict[atom].name atomSet = makeAtomSet(name, (atom, ), chemAtomSet, 'stereo') atomSets.append(atomSet) atomSetNames.append(name) resonanceSet = None for resonance in resonances: resonanceSet = assignAtomsToRes(atomSets, resonance, resonanceSet) for n, atom in enumerate(atoms): name = chemAtomSetDict[atom].name name2 = makeNonStereoName(molType, name, n) makeGuiMultiAtomSet(residue, name2, atomSetNames, elementSymbol, 'nonstereo', chemAtomSet) makeGuiMultiAtomSet(residue, groupName, atomSetNames, elementSymbol, 'ambiguous', chemAtomSet)
def duplicateResidueAssignments(residueA, residueB, experimentChains=None): """ Assign residueB to an equivalent set of resonances as residueA Optional dictionary, keyed by experiment to specifiy which chain (should be parent of residueA or residueB or None - for both) an experiment's peak assignments should go with. .. describe:: Input MolSystem.Residue, MolSystem.Residue, Dict of Nmr.Experiment:MolSystem.Chain (or None) .. describe:: Output None """ from ccpnmr.analysis.core.AssignmentBasic import assignResToDim project = residueA.root nmrProject = project.currentNmrProject atomSetDict = {} for atom in residueB.atoms: atomSet = atom.atomSet if atomSet: atomSetDict[atomSet.name] = atomSet if experimentChains is None: experimentChains = {} else: for experiment in experimentChains: chain = experimentChains[experiment] molSystems = experiment.molSystems if chain and chain.molSystem not in molSystems: experiment.addMolSystem(chain.molSystem) else: if residueA.chain.molSystem not in molSystems: experiment.addMolSystem(residueA.chain.molSystem) if residueB.chain.molSystem not in molSystems: experiment.addMolSystem(residueB.chain.molSystem) resonancesA = getResidueResonances(residueA) resonancesB = getResidueResonances(residueB) resonancesDictA = {} for resonance in resonancesA: atomSetNames = [ass.name for ass in resonance.resonanceSet.atomSets] atomSetNames.sort() key = tuple(atomSetNames) resonancesDictA[key] = resonancesDictA.get(key, []) + [ resonance, ] resonancesDictB = {} for resonance in resonancesB: atomSetNames = [ass.name for ass in resonance.resonanceSet.atomSets] atomSetNames.sort() key = tuple(atomSetNames) resonancesDictB[key] = resonancesDictB.get(key, []) + [ resonance, ] transfers = [] pureTransfer = True for key in resonancesDictA.keys(): resonances1 = resonancesDictA[key] resonances2 = resonancesDictB.get(key, []) atomSets = [] for atomSetName in key: if atomSetDict.has_key(atomSetName): atomSets.append(atomSetDict[atomSetName]) if len(atomSets) == len( key ): # If we find all equiv atom sets in destination (not always true if different res type) # Duplications of resonances is only done if needed at a per atomSet level doDuplicate = False contribs = set() for resonance1 in resonances1: contribs.update(resonance1.peakDimContribs) if contribs: for contrib in contribs: experiment = contrib.peakDim.peak.peakList.dataSource.experiment if experimentChains.get( experiment, residueB.chain ) is not residueB.chain: # Not a plain transfer doDuplicate = True pureTransfer = False break else: # All orphans for experiment in experimentChains: if experimentChains[experiment] is not residueB.chain: doDuplicate = True pureTransfer = False break if doDuplicate: # Not a plain transfer Need to make new resonances while len(resonances2) < len(resonances1): resonances2.append(None) for i, resonance1 in enumerate(resonances1): resonance2 = resonances2[i] peakDimContribs = list(resonance1.peakDimContribs) if peakDimContribs: for peakDimContrib in peakDimContribs: peakDim = peakDimContrib.peakDim experiment = peakDim.peak.peakList.dataSource.experiment chainB = experimentChains.get(experiment) if chainB is None: # Duplication on this peak if resonance2 is None: resonance2 = nmrProject.newResonance( isotopeCode=resonances1[0].isotopeCode) assignAtomsToRes(atomSets, resonance2) resonances2[i] = resonance2 assignResToDim(peakDim, resonance2, doWarning=False) elif chainB is residueB.chain: # Transfer this peak if resonance2 is None: resonance2 = nmrProject.newResonance( isotopeCode=resonances1[0].isotopeCode) assignAtomsToRes(atomSets, resonance2) resonances2[i] = resonance2 assignResToDim(peakDim, resonance2, doWarning=False) for peakContrib in peakDimContrib.peakContribs: if len(peakContrib.peakDimContribs) < 2: peakContrib.delete() if not peakDimContrib.isDeleted: peakDimContrib.delete() else: if resonance2 is None: resonance2 = nmrProject.newResonance( isotopeCode=resonances1[0].isotopeCode) assignAtomsToRes(atomSets, resonance2) resonances2[i] = resonance2 else: # Plain transfer, move existing resonances to different atoms transfers.append((resonances1, atomSets)) # Transfer original spin system to destination residue # to keep existing links and attrs (pure transfers only) spinSystem = nmrProject.findFirstResonanceGroup(residue=residueA) if spinSystem and pureTransfer: spinSystem.residue = residueB spinSystem.ccpCode = residueB.ccpCode spinSystem.chains = [ residueB.chain, ] # Clear all resonance to spinSystem links first so # that assigniment can pickup the original spin system for resonances, atomSets in transfers: for resonance in resonances: resonance.resonanceGroup = None for resonances, atomSets in transfers: for resonance in resonances: assignAtomsToRes(atomSets, resonance)
def assignResonances(resonances, atomToResonanceMap, molSystem, ccpnShiftList, AnalysisProject, nmrConstraintStore): print "assigning resonances" atomTupleDict = {} resonanceDict = {} fixedResonanceDict = {} cingFixedResonanceDict = {} for cingResonance in resonances: ccpnResidueArray = cingResonance.atom.residue.typeIdentifier.translate( 'CCPN').split() ccpnResidueName = ccpnResidueArray[1] if cingResonance.stereo == True: ### find the ccpnResonance from which the cingResonance originated and assign it. ringAtoms = [ 'CD1', 'CD2', 'CE1', 'CE2', 'HD1', 'HD2', 'HE1', 'HE2' ] ccpnRealAtomName = cingResonance.atom.typeIdentifier.translate( 'CCPN') if ccpnResidueName == 'Phe' and ccpnRealAtomName in ringAtoms: ccpnRealAtomName = ccpnRealAtomName[:2] + "*" if ccpnResidueName == 'Tyr' and ccpnRealAtomName in ringAtoms: ccpnRealAtomName = ccpnRealAtomName[:2] + "*" ccpnMappingAtomName = ccpnRealAtomName[0] + ccpnRealAtomName[ 1:].lower() if len(ccpnRealAtomName) == 1: ccpnMappingAtomName = ccpnRealAtomName else: ccpnMappingAtomName = ccpnRealAtomName[0] + ccpnRealAtomName[ 1:].lower() ccpnChainCode = molSystem.findFirstChain( code=cingResonance.atom.chainId) ccpnResNum = cingResonance.atom.sequenceId ccpnResidue = molSystem.findFirstChain().findFirstResidue( seqCode=ccpnResNum) ccpnResidueMapping = AnalysisProject.findFirstChainMapping( molSystemCode=molSystem.code, chainCode=cingResonance.atom.chainId).findFirstResidueMapping( seqId=ccpnResidue.seqId) ccpnAtomMapping = ccpnResidueMapping.findFirstAtomSetMapping( name=ccpnMappingAtomName) atomTuple = (ccpnChainCode, ccpnResidue.seqId, ccpnRealAtomName) if atomTuple not in atomTupleDict: atomTupleDict[atomTuple] = cingResonance resonance = atomToResonanceMap[atomTuple] assignAtomsToRes(ccpnAtomMapping.atomSets, resonance) # except KeyError: # pass else: ### find the ccpnResonance from which the cingResonance originated and assign it. ringAtoms = [ 'CD1', 'CD2', 'CE1', 'CE2', 'HD1', 'HD2', 'HE1', 'HE2' ] ccpnRealAtomName = cingResonance.atom.typeIdentifier.translate( 'CCPN') if ccpnResidueName == 'Phe' and ccpnRealAtomName in ringAtoms: ccpnRealAtomName = ccpnRealAtomName[:2] + "*" if ccpnResidueName == 'Tyr' and ccpnRealAtomName in ringAtoms: ccpnRealAtomName = ccpnRealAtomName[:2] + "*" ccpnChainCode = molSystem.findFirstChain( code=cingResonance.atom.chainId) ccpnResNum = cingResonance.atom.sequenceId ccpnResidue = molSystem.findFirstChain().findFirstResidue( seqCode=ccpnResNum) atomTuple = (ccpnChainCode, ccpnResidue.seqId, ccpnRealAtomName) if atomTuple not in atomTupleDict: atomTupleDict[atomTuple] = cingResonance for atomTuple in atomTupleDict: cingResonance = atomTupleDict[atomTuple] try: resonance = atomToResonanceMap[atomTuple] shift = ccpnShiftList.newShift(value=cingResonance.value, resonance=resonance) if resonance is not None: resonanceDict[cingResonance] = resonance fixedResonance = getFixedResonance(nmrConstraintStore, resonance) fixedResonanceDict[resonance] = fixedResonance cingFixedResonanceDict[cingResonance.atom] = fixedResonance except KeyError: pass return { "resonanceDict": resonanceDict, "fixedResonanceDict": fixedResonanceDict, "cingFixedResonanceDict": cingFixedResonanceDict } print "Resonances assigned"
def storeDihedralConstraints(self): if not self.dangleChain: return # make a new dihedralConstraintList head = self.constraintSet if not head: head = self.project.newNmrConstraintStore( nmrProject=self.nmrProject) self.constraintSet = head chain = self.dangleChain.chain shiftList = self.dangleChain.shiftList name = 'DANGLE Chain %s:%s ShiftList %d' % ( chain.molSystem.code, chain.code, shiftList.serial) constraintList = head.newDihedralConstraintList(name=name, measureListSerials=[ shiftList.serial, ]) # traverse the sequence and make appropriate constraint objects residues = chain.sortedResidues() for residue in residues: # Ensure we have atomSets etc getResidueMapping(residue) residueList = [(dr.residue.seqCode, dr.residue, dr) for dr in self.dangleChain.dangleResidues] residueList.sort() cnt = 0 for seqCode, residue, dangleResidue in residueList: phi = dangleResidue.phiValue psi = dangleResidue.psiValue if (phi is None) and (psi is None): continue # Use below functions because residues may not be sequentially numbered prevRes = getLinkedResidue(residue, 'prev') nextRes = getLinkedResidue(residue, 'next') if (prevRes is None) or (nextRes is None): continue C__1 = prevRes.findFirstAtom(name='C') # C (i-1) N_0 = residue.findFirstAtom(name='N') # N (i) CA_0 = residue.findFirstAtom(name='CA') # CA(i) C_0 = residue.findFirstAtom(name='C') # N (i) N_1 = nextRes.findFirstAtom(name='N') # C (i+1) # get fixedResonances fixedResonances = [] for atom in (C__1, N_0, CA_0, C_0, N_1): atomSet = atom.atomSet if atomSet.resonanceSets: resonance = atomSet.findFirstResonanceSet( ).findFirstResonance() else: # make new resonance if not atom.chemAtom: print 'no chem atom' ic = atom.chemAtom.elementSymbol if (ic == 'C'): ic = '13' + ic elif (ic == 'N'): ic = '15' + ic resonance = self.nmrProject.newResonance(isotopeCode=ic) assignAtomsToRes([ atomSet, ], resonance) fixedResonances.append(getFixedResonance(head, resonance)) # make dihedralConstraints phiResonances = (fixedResonances[0], fixedResonances[1], fixedResonances[2], fixedResonances[3]) phiConstraint = constraintList.newDihedralConstraint( resonances=phiResonances) psiResonances = (fixedResonances[1], fixedResonances[2], fixedResonances[3], fixedResonances[4]) psiConstraint = constraintList.newDihedralConstraint( resonances=psiResonances) # make constraint items if phi is not None: phiConstraint.newDihedralConstraintItem( targetValue=phi, upperLimit=dangleResidue.phiUpper, lowerLimit=dangleResidue.phiLower) cnt += 1 if psi is not None: psiConstraint.newDihedralConstraintItem( targetValue=psi, upperLimit=dangleResidue.psiUpper, lowerLimit=dangleResidue.psiLower) cnt += 1 showInfo('Success', 'DANGLE has generated %d dihedral restraints.' % cnt, parent=self)
def makeRandomCoilShiftList(molSystems): """ Make a synthetic chemical shift list using random coil values, adjusting protein backbone values for sequence where approprate. .. describe:: Input MolSystem.MolSystem .. describe:: Output Nmr.ShiftList """ from ccpnmr.analysis.core.AssignmentBasic import assignAtomsToRes from ccpnmr.analysis.core.MoleculeBasic import DEFAULT_ISOTOPES, getRandomCoilShift project = list(molSystems)[0].root done = set() nmr = project.currentNmrProject shiftList = nmr.newShiftList(isSimulated=True, unit='ppm', name='Random coil') resonanceDict = {} for molSystem in molSystems: for chain in molSystem.sortedChains(): if chain.molecule in done: continue done.add(chain.molecule) residues = chain.sortedResidues() n = len(residues) for i, residue in enumerate(residues): context = [None] * 5 for k, j in enumerate(range(i-2, i+3)): if 0 <= j < n: context[k] = residues[j] atomSets = set() for atom in residue.atoms: atomSet = atom.atomSet if atomSet: atomSets.add(atomSet) for atomSet in atomSets: atom = atomSet.findFirstAtom() chemAtom = atom.chemAtom value = getRandomCoilShift(chemAtom, context) if value is not None: resonanceSet = atomSet.findFirstResonanceSet() if resonanceSet: resonances = list(resonanceSet.resonances) index = list(resonanceSet.atomSets).index(atomSet) resonance = resonances[min(index, len(resonances)-1)] else: isotope = DEFAULT_ISOTOPES.get(atom.chemAtom.elementSymbol) if isotope is None: continue resonance = nmr.newResonance(isotopeCode=isotope) resonanceSet = assignAtomsToRes((atomSet,), resonance) resonanceDict[resonance] = value for resonance in resonanceDict: value = resonanceDict[resonance] shift = shiftList.newShift(value=value, resonance=resonance) return shiftList
def getCouplingAtomResonances(nmrProject, residue, atomNames, makeNew=True): """ Get resonances that correspond to two named atoms in a given residue context - could include sequential neighbours. A prerequisite for accessign the Jcoupling etc for those atoms. .. describe:: Input Nmr.NmrProject, MolSystem.Residue, 2-List of Words (MolSystem.Atom.names), Boolean .. describe:: Output Nmr.Resonance, Nmr.Resonance """ # Add FindLinkedresidue calls here so not relying on seqCode from ccpnmr.analysis.core.AssignmentBasic import assignAtomsToRes atomNames = tuple(atomNames) if 'C' in atomNames: if 'H' in atomNames: residueA = residueB = residue else: if 'C' == atomNames[0]: residueA = residue.chain.findFirstResidue( seqCode=residue.seqCode - 1) residueB = residue else: residueA = residue residueB = residue.chain.findFirstResidue( seqCode=residue.seqCode - 1) else: residueA = residueB = residue if not (residueA and residueB): return None, None atomA = residueA.findFirstAtom(name=atomNames[0]) atomB = residueB.findFirstAtom(name=atomNames[1]) resonanceA = None resonanceB = None if atomA and atomB: atomSetA = atomA.atomSet atomSetB = atomB.atomSet if atomSetA and atomSetB: resonanceSetsA = list(atomSetA.resonanceSets) resonanceSetsB = list(atomSetB.resonanceSets) if not resonanceSetsA: if makeNew: isotope = DEFAULT_ISOTOPES.get( atomA.chemAtom.elementSymbol) resonanceA = nmrProject.newResonance(isotopeCode=isotope) resonanceSetA = assignAtomsToRes([ atomSetA, ], resonanceA) else: resonanceSetA = resonanceSetsA[0] for resonanceSet in resonanceSetsA: if len(resonanceSet.resonances) < len( resonanceSetA.resonances): resonanceSetA = resonanceSet resonanceA = resonanceSetA.findFirstResonance() if not resonanceSetsB: if makeNew: isotope = DEFAULT_ISOTOPES.get( atomB.chemAtom.elementSymbol) resonanceB = nmrProject.newResonance(isotopeCode=isotope) resonanceSetB = assignAtomsToRes([ atomSetB, ], resonanceB) else: resonanceSetB = resonanceSetsB[0] for resonanceSet in resonanceSetsB: if len(resonanceSet.resonances) < len( resonanceSetB.resonances): resonanceSetB = resonanceSet resonanceB = resonanceSetB.findFirstResonance() return resonanceA, resonanceB
def startMd(self): self.setNumClouds() self.setFilePrefix() if ((self.constrLists != [None] * 4) and (self.numClouds > 0) and self.filePrefix): resDict = {} for resonance in self.guiParent.project.currentNmrProject.resonances: resDict[resonance.serial] = resonance constraints = [] constraintStore = None for dcl in self.constrLists: if dcl: constraintStore = dcl.nmrConstraintStore constraints.extend(list(dcl.constraints)) resonances = [] for constraint in constraints: for item in constraint.items: for fixedResonance in item.resonances: if fixedResonance.resonanceSerial is None: resonance = newResonance( self.guiParent.project, isotopeCode=fixedResonance.isotopeCode) resonance.setName(fixedResonance.name) fixedResonance.setResonanceSerial(resonance.serial) resDict[resonance.serial] = resonance if fixedResonance.resonanceSet: atomSets = list( fixedResonance.resonanceSet.atomSets) assignAtomsToRes(atomSets, resonance) if resDict.get( fixedResonance.resonanceSerial) is not None: resonances.append( resDict[fixedResonance.resonanceSerial]) resDict[fixedResonance.resonanceSerial] = None resonances, intraConstraintList = self.makeIntraConstraints( resonances, constraintStore) constraints.extend(list(intraConstraintList.constraints)) resonances, interConstraintList = self.makeInterConstraints( resonances, constraintStore) constraints.extend(list(interConstraintList.constraints)) startMdProcess(self.numClouds, constraints, resonances, self.coolingScheme, self.filePrefix) #structGen = self.distanceConstraintList.structureGeneration serials = [] for resonance in resonances: serials.append(resonance.serial) clouds = [] for i in range(self.numClouds): clouds.append('%s%3.3d.pdb' % (self.filePrefix, i)) self.guiParent.application.setValues(constraintStore, 'clouds', values=clouds) self.guiParent.application.setValues(constraintStore, 'cloudsResonances', values=serials)