I just noticed that my suggested code below has a bug...
currConf should hold the index of the current conformation and not a pointer
to it (because that memory address belongs to the source object).
So, below is the corrected code. Hopefully no noticeable bugs this time ;-)
Cheers,
Izhar
----------------
//Copy conformer
information
if (src.NumConformers() >
1)
{
int
k,l;
vector<double*>
conf;
int currConf =
-1;
double* xyz =
NULL;
for (k=0 ; k<src.NumConformers() ; ++k)
{
xyz = new double
[3*src.NumAtoms()];
memcpy( xyz, src.GetConformer(k), sizeof( double )*3*src.NumAtoms()
);
conf.push_back(xyz);
if( src.GetConformer(k) == src._c )
{
currConf =
k;
}
}
SetConformers(conf);
if( currConf >= 0 && _vconf.size() )
{
_c =
_vconf[currConf];
}
}
On Wed, Jul 13, 2011 at 2:31 PM, Izhar Wallach <izh...@cs.toronto.edu>wrote:
> Hi all,
>
> I noticed that when a molecule has multiple conformations the assignment
> operator in OBMol does not copy properly the active conformation but rather
> sets it to be the first one in the conformation set.
> I guess this happens because the molecule object does not "remember" the
> index of the currently active one but rather just points to it.
>
> It seems to me this is more of a bug than a feature because when copying a
> molecule one expects to copy its full state and not resets it to some
> arbitrary configuration.
>
> Below are my suggested small modifications to the code in mol.cpp (line
> #~1300) that solve this issue (given the right commit permissions I will
> modify the code directly...).
>
> Thanks,
> Izhar
> --------------------------
> //Copy conformer
> information
>
> if (src.NumConformers() > 1) {
> int k,l;
> vector<double*> conf;
> double* currConf = NULL; // NEW
>
>
> double* xyz = NULL;
> for (k=0 ; k<src.NumConformers() ; ++k) {
> xyz = new double [3*src.NumAtoms()];
> //for (l=0 ; l<(int) (3*src.NumAtoms()) ;
> ++l)
>
> // xyz[l] = src.GetConformer(k)[l];
> memcpy( xyz, src.GetConformer(k), sizeof( double
> )*3*src.NumAtoms() ); // while we are here, this is more efficient than the
> above loop
> conf.push_back(xyz);
>
> if( src.GetConformer(k) == src._c ) { // NEW
>
>
> currConf =
> src._c;
>
>
> }
>
> }
>
> SetConformers(conf);
>
> if( currConf ) { // NEW
>
>
> _c =
> currConf;
>
>
> }
>
> }
>
>
------------------------------------------------------------------------------
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel