Right, that makes sense. When you delete atoms, Jmol does not actually
remove them. It just marks them as "deleted". This is to save time and lower
the chance of all sorts of problems later. So your value for "i" will be
off. You need this:

select atomIndex=_atomPicked;
flash
var x = {atomIndex=_atomPicked}.atomX;
var y = {atomIndex=_atomPicked}.atomY+.1;
var z = {atomIndex=_atomPicked}.atomZ+.1;
set appendNew false;
var w = '1\ntest\nC ' + x + ' ' + y + ' ' + z + '\n';
print "A " + {*}.length + " " + _atomPicked
data 'append @w';
print "B " + {*}.length + " " + _atomPicked + {atomIndex=_atomPicked}
var i = {*}[0].atomIndex
connect (atomIndex=_atomPicked) (atomIndex=i) single;

You might consider a different way to add that atom position:

var a = {atomIndex=_atomPicked};
select a
flash
var pt = a.xyz * 2 - {connected(a)}.xyz
set appendNew false;
var w = '1\ntest\nC ' + pt.x + ' ' + pt.y + ' ' + pt.z + '\n';
data 'append @w';
var b = {*}[0]
connect @a @b single;


On Mon, Mar 22, 2010 at 11:29 PM, Otis Rothenberger <[email protected]>wrote:

> Bob,
>
> I am having an atom index problem building a carbon chain. I set the stage
> for this with the following script:
>
> delete hydrogens;echo Clicked atoms will|ADD a carbon atom.;
>
> If at this point I check atomIndexes, and they are A-OK. The hydrogens are
> gone, and the atomIndexes run from 0 to the new number of atoms -1.
>
> The carbon atom click/add then uses the following script:
>
> select atomIndex=_atomPicked;flash;var i = {*}.atomIndex.max + 1;var j = i
> + 1;var x = {atomIndex=_atomPicked}.atomX;var y =
> {atomIndex=_atomPicked}.atomY+.1;var z =
> {atomIndex=_atomPicked}.atomZ+.1;set appendNew false;var w = '1\ntest\nC ' +
> x + ' ' + y + ' ' + z + '\n';data 'append @w';connect
> (atomIndex=_atomPicked) (atomIndex=i) single;
>
> Flash is my own command that simply substitutes the Jmol script to flash
> the atom magenta for .5 seconds prior to jmolScript()
>
> If I do NOT delete the hydrogens (step 1 above), then the script works
> nicely. If I do delete the hydrogens (step 1 again) the first click/add
> fails to bond -
>
>  i.e. connect (atomIndex=_atomPicked) (atomIndex=i) single
>
> is failing. The new carbon atom is added, but it floats away without
> connecting on a subsequent minimize. After this first failure, the script
> works on subsequent clicks.
>
> I could simply leave the hydrogens on, but I'm trying to give the editor
> the feel of standard editors that build C frameworks.
>
> The working page is here:
>
> http://chemagic.com/web_molecules/script_page_large.aspx
>
> Click Display Control Panel.
>
> The page is set to do the with-hydrogen edit (works). If you do a delete
> hydrogens in the text command field, you will see the problem on the first C
> add.
>
> Any thoughts on the problem? It appears for the first click atomIndex=i is
> not what I think it is??
>
> Otis
>
> --
> Otis Rothenberger
> http://chemagic.org
>
>
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> Jmol-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jmol-users
>
>


-- 
Robert M. Hanson
Professor of Chemistry
St. Olaf College
1520 St. Olaf Ave.
Northfield, MN 55057
http://www.stolaf.edu/people/hansonr
phone: 507-786-3107


If nature does not answer first what we want,
it is better to take what answer we get.

-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Jmol-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to