Bug in Velocity3D

1 view
Skip to first unread message

julien

unread,
Feb 9, 2011, 6:42:43 PM2/9/11
to Sire Developers
What steps will reproduce the problem?

from Sire.Mol import *
from Sire.IO import *
from Sire.Vol import *
from Sire.FF import *
from Sire.MM import *
from Sire.CAS import *
from Sire.Maths import *
from Sire.Qt import *
from Sire.Units import *
from Sire.System import *
from Sire.Base import *
from Sire.Move import *
from Sire.Stream import *

import sys

mols = PDB().read("start.pdb")
temperature = 300 * kelvin
velocity_gen = MaxwellBoltzmann(temperature)
mol1 = mols.molecule(MolNum(1))
print velocity_gen.generate(mol1)
print velocity_gen.generate(mol1)
print velocity_gen.generate(mol1)

What is the expected output? What do you see instead?

the third component of the vector is always null

This is because there is a bug in corelib/src/libs/SireMaths/
vector3d.hpp
line 152
sc[3] = T(v.z());
should be
sc[2] = T(v.z());


Christopher Woods

unread,
Feb 10, 2011, 4:23:19 AM2/10/11
to sire-de...@googlegroups.com
Hi Julien,

Yes - it is a bug in the copy constructor for Vector3D. Thanks for
spotting it :-).

The current code reads;

/** Construct from the passed vector - this assumes that
the vector is already in internal units */
template<class T>
SIRE_OUTOFLINE_TEMPLATE
Vector3D<T>::Vector3D(const Vector &v)
{
sc[0] = T(v.x());
sc[1] = T(v.y());
sc[3] = T(v.z());
}

It should be changed to;

/** Construct from the passed vector - this assumes that
the vector is already in internal units */
template<class T>
SIRE_OUTOFLINE_TEMPLATE
Vector3D<T>::Vector3D(const Vector &v)
{
sc[0] = T(v.x());
sc[1] = T(v.y());
sc[2] = T(v.z());
}

(the variable sc[3] was being used instead of sc[2]. I am surprised
that this never caused a crash!)

I've updated the code in "devel", which will be committed during my next commit.

Cheers,

Christopher

Reply all
Reply to author
Forward
0 new messages