Sire extension using OpenMM

36 views
Skip to first unread message

Gaetano Calabrò

unread,
Feb 14, 2012, 5:13:50 AM2/14/12
to Sire Developers
Hello,

I'm trying to extend Sire to perform MD simulations using the OpenMM
API. I have extracted the positions and velocities using the
AtomicVelocityWorkspace class in Sire. In order to pass back the
OpenMM data I need to update the “atom_coords and atom_momenta”
vectors of the class AtomicVelocityWorkspace (SireMove/
integratorworkspace.h) but these vectors are declared as private. I'd
like to know what is a “reasonable” way to update these vectors
without changing a lot the code of Sire keeping its “logic and
structures”.

Kind Regards,

Gaetano

Christopher

unread,
Feb 14, 2012, 5:28:13 AM2/14/12
to Sire Developers

Hi Gaetano,

The best way to do it is to use the same methods as in
"VelocityVerlet::integrate(...)". You can get the raw pointers into
the atom_coords and atom_momenta arrays via the "coordsArray" and
"momentaArray" member functions of AtomicVelocityWorkspace. These
return the pointers to the arrays for the ith molecule in the
workspace. You can get the size of the ith array by using the "nAtoms"
function of AtomicVelocityWorkspace to get the number of atoms in the
ith molecule.

For example, if you have the velocities and coordinates from OpenMM in
one set of arrays, then you could use memcpy or qMemCopy to block copy
the data, e.g.

AtomicVelocityWorkspace ws = ...;

for (int i=0; i<nmols; ++i)
{
int nats = ws.nAtoms(i);

Vector *coords = ws.coordsArray(i);
Vector *momenta = ws.momentaArray(i);

qMemCopy(coords, openmm_coords[i], nats * sizeof(Vector));
qMemCopy(momenta, openmm_momenta[i], nats * sizeof(Vector));
}

or, if you wanted to copy directly, as perhaps the OpenMM arrays have
a different layout, then use;

for (int i=0; i<nmols; ++i)
{
int nats = ws.nAtoms(i);

Vector *coords = ws.coordsArray(i);
Vector *momenta = ws.momentaArray(i);

for (int j=0; j<nats; ++j)
{
coords[j] = Vector( openmm_coords[i][j].x, openmm_coords[i]
[j].y, openmm_coords[i][j].z );
momenta[j] = Vector( openmm_momenta[i][j].x, openmm_momenta[i]
[j].y, openmm_momenta[i][j].z );
}
}

I hope this helps. Please feel to email more, or email me code if you
want more help :-)

Best wishes,

Christopher

Gaetano Calabrò

unread,
Feb 22, 2012, 5:31:20 AM2/22/12
to Sire Developers
Hi Christopher,

Thanks a lot for your prompt reply. I was able to pass back my data
following your code.

Kind Regards,

Gaetano
Reply all
Reply to author
Forward
0 new messages