Re: [AMBER] modifying cpptraj

From: Daniel Roe <daniel.r.roe.gmail.com>
Date: Fri, 12 Jun 2015 14:19:46 -0600

Hi,

For future reference, issues like this are better sent to the Amber
developer's list, http://lists.ambermd.org/mailman/listinfo/amber-developers
- I think most people are probably bored by the details of cpptraj code :-)

On Fri, Jun 12, 2015 at 11:16 AM, Gard Nelson <Gard.Nelson.nantbio.com>
wrote:

> // Upper Triangle
> for (AtomMask::const_iterator atom2 = mask1_.begin(); atom2 !=
> mask1_.end(); ++atom2)
> for (AtomMask::const_iterator atom1 = atom2; atom1 != mask1_.end();
> ++atom1)
> dst = sqrt(DIST2_NoImage(currentFrame.XYZ(*atom2),
> currentFrame.XYZ(*atom1)));
> *(mat++) += dst;
>

Your problem is that in the inner loop instead of a single statement you
now have *two* statements you want to execute, which in C/C++ require the
creation of a code block enclosed in curly braces ({}), e.g.

for (AtomMask::const_iterator atom2 = mask1_.begin(); atom2 !=
mask1_.end(); ++atom2)
  for (AtomMask::const_iterator atom1 = atom2; atom1 != mask1_.end();
++atom1) {
    dst = sqrt(DIST2_NoImage(currentFrame.XYZ(*atom2),
currentFrame.XYZ(*atom1)));
    *(mat++) += dst;
  }

In your code, the 'dst =' statement is executed within the inner loop, but
the *(mat++) statement is executed outside both loops. Therefore all the
values you calculate except the last one are lost, and that final value is
the only one added to the matrix.

Hope this helps,

-Dan


> } else {
> // Full matrix
> for (AtomMask::const_iterator atom2 = mask2_.begin(); atom2 !=
> mask2_.end(); ++atom2)
> for (AtomMask::const_iterator atom1 = mask1_.begin(); atom1 !=
> mask1_.end(); ++atom1)
> dst = sqrt(DIST2_NoImage(currentFrame.XYZ(*atom2),
> currentFrame.XYZ(*atom1)));
> *(mat++) += dst;
> }
> }
> The function I want to implement uses the distance in several places, so
> making multiple calls to DIST2_NoImage slows things down dramatically. All
> I intended to do with the above code is assign the distance to a variable
> and then add that variable to the matrix. I could then use that variable
> (dst) wherever it's needed.
>
> However, making this change results in the output matrix having a small
> value in the (1,1) position and being uniformly 0 everywhere else, which is
> not the functionality I expected. I am stumped over why the change I made
> isn't transparent and would greatly appreciate any help in making the code
> work.
> Thanks,
> Gard
>
> CONFIDENTIALITY NOTICE
> This e-mail message and any attachments are only for the use of the
> intended recipient and may contain information that is privileged,
> confidential or exempt from disclosure under applicable law. If you are not
> the intended recipient, any disclosure, distribution or other use of this
> e-mail message or attachments is prohibited. If you have received this
> e-mail message in error, please delete and notify the sender immediately.
> Thank you.
> _______________________________________________
> AMBER mailing list
> AMBER.ambermd.org
> http://lists.ambermd.org/mailman/listinfo/amber
>



-- 
-------------------------
Daniel R. Roe, PhD
Department of Medicinal Chemistry
University of Utah
30 South 2000 East, Room 307
Salt Lake City, UT 84112-5820
http://home.chpc.utah.edu/~cheatham/
(801) 587-9652
(801) 585-6208 (Fax)
_______________________________________________
AMBER mailing list
AMBER.ambermd.org
http://lists.ambermd.org/mailman/listinfo/amber
Received on Fri Jun 12 2015 - 13:30:03 PDT
Custom Search