[chimera-dev] mixing names

Eric Pettersen pett at cgl.ucsf.edu
Tue Oct 14 10:50:04 PDT 2008


Hi Patrick,
	chimera.Atom is the Atom class, so with this statement:

at1=chimera.Atom

	you are simply providing an alternate name (at1) for the chimera.Atom  
class, not instantiating an Atom.  So therefore with this statement:

at1.name="BC1"

	you are assigning the Atom class attribute "name" to be "BC1".   
Therefore, whenever the "name" attribute is looked up in any Atom  
instance after that, it finds the class assignment first and uses  
that, which is why all the atoms seem to have the name BC1 afterward.

	In Chimera, you can't create an Atom "directly" -- you have to have a  
Molecule instance, which in turn has a method for adding Atoms.  One  
of the simpler ways of adding Atoms is to use  
chimera.molEdit.addAtom().  That function has a pretty good doc string  
describing its arguments.  Before you can use that function though you  
need to create a Molecule and Residue instance to contain the Atom.   
Look at the _newModel and _newResidue methods of BuildStructure/ 
__init__.py for example code for that.
	There's a somewhat useful handout we made for a Chimera programming  
class this summer that you may want to look over.  It's available as a  
link off the Chimera Programmer's Guide page: http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/index.html

--Eric

                         Eric Pettersen
                         UCSF Computer Graphics Lab
                         http://www.cgl.ucsf.edu


On Oct 14, 2008, at 7:45 AM, Patrick Ladam wrote:

> Hello to the list,
> I start trying to write my first py code in chimera (not that easy
> without too much doc strings) and have a first question to submit.
>
> Here is what I am doing in IDLE:
>
>>>> import chimera
>>>> opened = chimera.openModels.open('1zik.pdb')
>
>>>> mol = opened[0]
>>>> for i in mol.atoms:
> 	print i.name
>
> N
> CA
> CB
> CG
> CD
> .../...
>
> # Now I want to instanciate an atom and set its name attribute:
>
>>>> at1=chimera.Atom
>>>> at1.name="BC1"
>>>> print at1.name
> BC1
>>>>
>
> # Now I redo the previous loop:
>
>>>> for i in mol.atoms:
> 	print i.name
>
> 	
> BC1
> BC1
> BC1
> BC1
> BC1
> BC1
> BC1
> BC1
> BC1
> BC1
> BC1
> BC1
> .../...
>
> They're all BC1!!!
>
> How come ? My created atom 'at1' and my 'mol' are supposed to be
> completely seperated objects no?
>
> Can someone help, I am afraid I missed something really basic here...
> Bye to all
> _______________________________________________
> Chimera-dev mailing list
> Chimera-dev at cgl.ucsf.edu
> http://www.cgl.ucsf.edu/mailman/listinfo/chimera-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-dev/attachments/20081014/8d52b512/attachment.html>


More information about the Chimera-dev mailing list