| | 34 | ==== Attributes: To Copy or Not to Copy, that is the question! ==== |
| | 35 | |
| | 36 | From the [http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/faq.html FAQ], item (7): Some attributes return a copy of an object. |
| | 37 | {{{ |
| | 38 | >>> xf = model.openState.xform # xf is a copy of the model's Xform matrix. |
| | 39 | >>> xf.zRotate(45) # This will not rotate the model. |
| | 40 | |
| | 41 | >>> c = model.atoms[0].color # c is the MaterialColor object for the atom |
| | 42 | >>> c.ambientDiffuse = (1,0,0) # The Atom color changes immediately to red. |
| | 43 | }}} |
| | 44 | |
| | 45 | Some Chimera objects returned as attributes are always copies, some are always references to the uncopied object. Objects that are always copied include Xform, Vector, Point, Sphere, Element, MolResId, Coord, .... Objects that are never copied include Atom, Bond, PseudoBond, CoordSet, Molecule, Residue, RibbonStyle, .... Object that can be copied have a __copy__ method. In order to know if an object type is passed by value is to look at the Chimera C++ header files. Classes without a WrapPy base class are always copied. This base class is part of the C++ to Python interface generation. |
| | 46 | |
| | 47 | |