Dear Gary,
What you have will work fine.
I would probably do something very similar:
def getIsotope(project, symbol, massNumber):
result = None
chemElementStore = project.findFirstChemElementStore()
if chemElementStore is not None:
chem_element = chemElementStore.findFirstChemElement(symbol=symbol)
if chem_element is not None:
result = chem_element.findFirstIsotope(massNumber=massNumber)
return result
Notes:
- findFirstXyz returns the first one found if called without parameters,
and None if nothing is found.
- I tend to use 'if xx is not None' where I can instead of 'if xx'.
A matter of style, but in rare cases 'if xx' can call internal object
functions that take longer to evaluate.
There are a couple of shortcuts, but they are more obscure. The 'getByKey'
function would work, but it will change soon. In the version 2 release
(any month now) that would be :
from ccp.api.molecule.ChemElement import Isotope
result = Isotope.getByKey(project.findFirstChemElementStore, symbol,
massNumber)
There is also a getByNavigation function for one-shot long-distance
navigation through a lot of links, but that has a very obscure syntax.
Yours,
Rasmus
---------------------------------------------------------------------------
Dr. Rasmus H. Fogh Email: [log in to unmask]
Dept. of Biochemistry, University of Cambridge,
80 Tennis Court Road, Cambridge CB2 1GA, UK. FAX (01223)766002
On Wed, 23 Jan 2008, Gary Thompson wrote:
> Gary Thompson wrote:
> > Rasmus Fogh wrote:
> >> Dear Gary,
> >>
> >> Isotope Codes are strings, like '13C', '1H', etc. Isotopes are objects,
> >> living in the molecule...
> > Hi Rasmus
> >
> > many thanks that makes everything clear ;-)
> >
> > regards
> > gary
> nb so this is what I cam up with for getIsotope:
>
> # todo add a default chemElementStore key e.g. ccpn?
> def getIsotope(project,symbol,massNumber):
> result = None
>
> chem_element = None
>
> chem_element =
> project.chemElementStores[0].findFirstChemElement(symbol=symbol)
> if chem_element:
> result = chem_element.findFirstIsotope(massNumber = massNumber)
>
> return result
>
> is this the best way to do it?
>
> regards
> gary
>
> --
> -------------------------------------------------------------------
> Dr Gary Thompson
> Astbury Centre for Structural Molecular Biology,
> University of Leeds, Astbury Building,
> Leeds, LS2 9JT, West-Yorkshire, UK Tel. +44-113-3433024
> email: [log in to unmask] Fax +44-113-2331407
> -------------------------------------------------------------------
>
|