
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

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@cgl.ucsf.edu http://www.cgl.ucsf.edu/mailman/listinfo/chimera-dev

Hi Patrick, Here's some Python code that illustrates making atoms. It copies a Chimera molecule (taken from chimera/share/PDBmatrices/copymolecule.py). Tom 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@cgl.ucsf.edu http://www.cgl.ucsf.edu/mailman/listinfo/chimera-dev
# ----------------------------------------------------------------------------- # def copy_molecule(m): import chimera cm = chimera.Molecule() for attr in ('name', 'openedAs'): if hasattr(m, attr): setattr(cm, attr, getattr(m,attr)) if hasattr(m, 'pdbHeaders'): cm.setAllPDBHeaders(m.pdbHeaders) rmap = {} for r in m.residues: cr = cm.newResidue(r.type, r.id) cr.isHelix = r.isHelix cr.isSheet = r.isSheet cr.isTurn = r.isTurn rmap[r] = cr amap = {} for a in m.atoms: ca = cm.newAtom(a.name, a.element) ca.setCoord(a.coord()) ca.altLoc = a.altLoc if hasattr(a, 'bfactor'): ca.bfactor = a.bfactor amap[a] = ca cr = rmap[a.residue] cr.addAtom(ca) for b in m.bonds: a1, a2 = b.atoms cm.newBond(amap[a1], amap[a2]) return cm
participants (3)
-
Eric Pettersen
-
Patrick Ladam
-
Tom Goddard