VMD-L Mailing List
From: Axel Kohlmeyer (akohlmey_at_cmm.chem.upenn.edu)
Date: Fri Jul 11 2008 - 09:37:49 CDT
- Next message: David Tanner: "Re: pick atom id script"
- Previous message: Leonardo Trabuco: "Re: QR factorization for structural alignment"
- In reply to: Abu Naser: "pick atom id script"
- Next in thread: David Tanner: "Re: pick atom id script"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
On Fri, 11 Jul 2008, Abu Naser wrote:
AN>
AN> hi all user,
AN>
AN> I wanted to pick atom index from the screen and append them to a
AN> file. I wrote a script for that and pasted below. I also want to add
AN> one to the index. I tried many ways and could not figure out how to
index+1 is serial
please see the atomselect documentation.
AN> do that. I would appreciate if anybody let me know that.
you want _us_ to tell _you_ that you cannot figure out what to do???
i assume that is not what you wanted to write, right? ;-)
AN> with regards,
AN>
AN> Abu
AN>
AN> proc id_pick {} {
AN> # get the atom and molecule picked
AN> global vmd_pick_atom vmd_pick_mol
AN> # get the coordinates
if you have comments in your code, please make sure that
they actually correspond to what the code does. if you don't
it can be _very_ confusing if you write a script and then have
to edit it much later and do not remember what you did. if you
follow the comments, you will be wrong...
=> wrong comments are worse than no comments.
good code is actually pretty self evident and the comments
need to not describe what the code does, but 'why' (where needed).
AN> set sel [atomselect $vmd_pick_mol "same residue as index $vmd_pick_atom"]
AN> # get residue name and id
AN> set atom [atomselect $vmd_pick_mol "index $vmd_pick_atom"]
AN> lassign [$atom get {name index}] name index
please read the atomselect documentation. the selection always returns
a list of lists. so this piece cannot work.
AN> # print the result
AN> set f [open "index.txt" a]
AN> puts $f "$name $index"
AN> close $f
also, you create atom selections, but do not delete them.
_very_ bad habit that will lead to a memory leak. in this
specific case, it will probably not matter at all, but one
has to get into the habit of _always_ deleting atom selections
at the appropriate place, so that in the few cases where it
matters, you do it the right way by force of habit already
and avoid a lot of frustration and debugging time.
this actually warrants a general remark. many people write
small scripts under the premise "i can do dirty hacks as
this won't matter and writing it in a clean way will waste
so much of my time". in the long run, it can become a serious
problem due to force of habit. it is very hard to get rid of
bad habits once they are well estabilished, or in short:
big problems should be taken lightly but
small problems should be taken seriously.
cheers,
axel.
AN> }
AN>
AN> proc id_pick_trace_fctn {args} {
AN> id_pick
AN> }
AN>
AN> trace variable vmd_pick_atom w id_pick_trace_fctn
AN> trace vdelete vmd_pick_atom w id_pick_trace_fctn
AN>
AN>
-- ======================================================================= Axel Kohlmeyer akohlmey_at_cmm.chem.upenn.edu http://www.cmm.upenn.edu Center for Molecular Modeling -- University of Pennsylvania Department of Chemistry, 231 S.34th Street, Philadelphia, PA 19104-6323 tel: 1-215-898-1582, fax: 1-215-573-6233, office-tel: 1-215-898-5425 ======================================================================= If you make something idiot-proof, the universe creates a better idiot.
- Next message: David Tanner: "Re: pick atom id script"
- Previous message: Leonardo Trabuco: "Re: QR factorization for structural alignment"
- In reply to: Abu Naser: "pick atom id script"
- Next in thread: David Tanner: "Re: pick atom id script"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]