OK Took me a couple of days where Tim would have done it in about 10 mins
but I think the attached file will do the type of copy you want (peaks
assigned to a MolSystem should be assigned to a preexisting copy in
another MolSystem). This is a fairly unsophisticated script with no error
checking and currently should be just pasted onto the python command line.
All the assignments (i.e. resonances that are specifically assigned) from
a selected ShiftList will be transfered.
DO test this for yourself on a test project with only a few assignments
first.
DO make a backup of your "production" project before you try it there!
KNOWN BUGS:
The dialog for selecting the molecular system blocks for me and won't
accept typing (but will accept the mouse click). I've been having issues
with SCIM messing about with my keyboard input under Gnome on FC6 - so I'd
be interested to hear if others have the same problem. Just put your
destination MolSystem code where it says 'MS2' if you have the same
problem.
TO DO:
1. Test, test, test.
2. Make it into a macro
3. More sophisticated feedback to user about unassigned resonances etc.
--
Dr. Brian O. Smith ---------------------- B Smith at bio gla ac uk
Division of Biochemistry & Molecular Biology,
Institute Biomedical & Life Sciences,
Joseph Black Building, University of Glasgow, Glasgow G12 8QQ, UK.
Tel: 0141 330 5167/6459/3089 Fax: 0141 330 8640
#prototype for function to copy assignments from one MolSystem to another
#
#assumes chain etc is identical. Only MolSystem is different.
from ccpnmr.analysis.AssignmentBasic import newResonance assignAtomsToRes initResonance assignResToDim
#will allow you to select a shiftList - should pop up a selection box
shiftList=top.argumentServer.getShiftList()
#will allow you to select a destination MolSystem - should pop up an input box
#seems to block everything and not accept keyboard input (but mouse clicks OK)
destMS=top.argumentServer.askString('Type in destination MolSystem code','MS2')
#gets you all the shiftList entries
measurements = shiftList.measurements
#loop over measurements
i=0 #counter for which Shift has no resonances message
for measurement in measurements:
i=i+1
if hasattr(measurement, 'resonance'):
#if a resonance is assigned it has a resonanceSet attribute
if (hasattr(measurement.resonance, 'resonanceSet') and (measurement.resonance.resonanceSet is not None)):
#all atoms in an atomSet should be in the same residue
#and we need atomSets for the assignAtomsToRes()
#so no need to go to individual atoms here
resonance=measurement.resonance
atomSet=resonance.resonanceSet.findFirstAtomSet()
residue=atomSet.findFirstAtom().residue
residueSeqId=residue.seqId
chainCode=residue.chain.code
#find the matching atom set in the new MolSystem
newResidue=top.project.findFirstMolSystem(code=destMS).findFirstChain(code=chainCode).findFirstResidue(seqId=residueSeqId)
#no direct link from residues to AtomSets so have to go via Atoms
#build a dictionary of atomSets in this residue keyed by name
aSets={}
for atom in newResidue.atoms:
aSet=atom.atomSet
aSets[aSet.name]=aSet
#retreive the right AtomSet based on name
newAtomSet=aSets[atomSet.name]
#make it into a list for assignAtomsToRes()
newAtomSets=[newAtomSet]
#make a new resonance
newReson = newResonance(top.project)
#assign atoms to new resonance.
#Leave setting resonanceSet to internals of assignAtomsToRes() hopefully.
assignAtomsToRes(newAtomSets,newReson)
#might need to initResonance() to create GUI name etc.
#initResonance(newReson)
#
#Now find peaks from shiftList assigned to old resonance and assign to newReson
for contrib in resonance.peakDimContribs:
#This function of Tim's makes this bit a lot easier than I thought!
assignResToDim(contrib.peakDim,newReson,contrib)
#
#otherwise it's not assigned - can't associate it with a new MS -
#have to do that at spectrum level
else:
print "Unassigned resonance not transfered to new MolSystem"
print " remember to reassociate your spectra with the new MolSystem"
else:
#To do: add counter info to enable identification
print "Measurement with no resonances not transfered"
|