[gmx-users] mdatoms->massA pointer dereferencing

Inon Sharony InonShar at TAU.ac.IL
Tue Aug 31 09:46:51 CEST 2010

Good morning!

I'm having C trouble with something which should be simple enough: 
GROMACS uses a struct called mdatoms which, amongst other things, houses 
the atom masses during the simulation. I'm trying to access this data 
(an array of the masses of all atoms). I've tried to consult internet 
sources and my local tech support team, but it seems the problem is that 
I'm misunderstanding the GROMACS programing. Any help would be greatly 
As I understand it, there's mdatoms, which is comprised of various stuff 
among which is the pointer massA.

 From mdatom.c:

line 209: md->massA[i] = mA;

Since md and mdatoms are of the same struct type, I believe 
mdatoms->massA is the pointer to the array I'm looking for.

I've tried all these various combinations in the attempt to access the 
elements of this array, to no avail...

In md.c:

include <mdatoms.h>
t_mdatoms.h *mdatoms
line 447: ...mdatoms->massT...
if (bFirstStep){
fprintf(stderr,"%g ",mdatoms->massA[trajectory_atom]); //segmentation 
// fprintf(trajectory,"%g ",mdatoms->massA->trajectory_atom); //error: 
request for member ‘trajectory_atom’ in something not a structure or 
// fprintf(trajectory,"%g ",mdatoms->massA.trajectory_atom); //error: 
request for member ‘trajectory_atom’ in something not a structure or 
// real *atomsmasses = mdatoms->massA;fprintf(trajectory,"%g 
",atomsmasses[trajectory_atom]);//segfault on run-time
// fprintf(trajectory,"%g ",mdatoms->tmassA); works, on the other hand, 
tmassA being a number rather than pointer or array

The command I issue and the output is:

~$ mdrun_d -quiet -v -pd -nt 1

:-) G R O M A C S (-:

GROup of MAchos and Cynical Suckers

:-) VERSION 4.5-beta4 (-:

Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
Copyright (c) 1991-2000, University of Groningen, The Netherlands.
Copyright (c) 2001-2008, The GROMACS development team,
check out http://www.gromacs.org for more information.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

:-) mdrun_d (double precision) (-:

Back Off! I just backed up md.log to ./#md.log.3#
Getting Loaded...
Reading file topol.tpr, VERSION 4.5-beta2 (double precision)
Note: tpx file_version 71, software version 73
Loaded with Money

Back Off! I just backed up traj.trr to ./#traj.trr.3#

Back Off! I just backed up ener.edr to ./#ener.edr.3#
starting mdrun 'Single Atom of Sulfur Between Two Gold Atoms'
6 steps, 0.0 ps.

Segmentation fault

The last two lines mean that the loop is entered ( trajectory_atom gets 
value zero ) and as soon as "md->massA[trajectory_atom]" is accessed, 
the program crashes. This was the result I got before. I tried accessing 
only elements 1 and above (by changing trajectory_atom to 
trajectory_atom+1 ) but got the same result.


Inon Sharony
ינון שרוני
Please consider your environmental responsibility before printing this e-mail.

More information about the gromacs.org_gmx-users mailing list