Dear Craig,
sorry, of course you are right. I was at home when I replied to your
e-mail and I thought to remember that I had put printf() before and
after Clear(), but I did not remember correctly; actually I had put them
before and after AddAtom().
The real issue was the length of _type in OBAtom (atom.h) being set to
6; when OBTypeTable::Translate(char *to, const char *from) (data.cpp) is
called, sizeof(to) = 8, so 2 more bytes are written. Guess what comes
after _type in OBAtom? _fcharge, which is a short. So it gets wiped to
zero by strncpy because of buffer overflow.
Chris, I guess it does not happen on Windows because Visual C pads data
to 8 bytes, or something like that.
So setting _type length from [6] to [8] in OBAtom fixes the problem.
Very happy to have nailed this bug which was annoying me since a long
time, even if that workaround kind of fixed it.
Therefore, forget about my previous patch and just apply the one
attached, which reverts the one which was applied some time ago on SVN
(which is now useless), uniforms "A T O M T Y P E" logging to the one
adopted in forcefieldgaff.cpp, forcefieldghemical.cpp and
forcefielduff.cpp and, most importantly, patches atom.h.
Cheers,
p.
--
==========================================================
Paolo Tosco, Ph.D. Phone: +39 011 6707680
Department of Drug Science Fax: +39 011 6707687
and Technology Mob: +39 348 5537206
Via Pietro Giuria, 9
10125 Torino, Italy
http://open3dalign.org
E-mail: [email protected] http://open3dqsar.org
==========================================================
*** src/forcefield.cpp.orig 2012-05-18 00:22:20.875386817 +0200
--- src/forcefield.cpp 2012-05-18 00:26:12.030386712 +0200
***************
*** 779,788 ****
{
IF_OBFF_LOGLVL_LOW {
OBFFLog("\nA T O M T Y P E S\n\n");
! OBFFLog("IDX\tTYPE\n");
FOR_ATOMS_OF_MOL (a, _mol) {
! snprintf(_logbuf, BUFF_SIZE, "%d\t%s\n", a->GetIdx(), a->GetType());
OBFFLog(_logbuf);
}
}
--- 779,789 ----
{
IF_OBFF_LOGLVL_LOW {
OBFFLog("\nA T O M T Y P E S\n\n");
! OBFFLog("IDX\tTYPE\tRING\n");
FOR_ATOMS_OF_MOL (a, _mol) {
! snprintf(_logbuf, BUFF_SIZE, "%d\t%s\t%s\n", a->GetIdx(),
a->GetType(),
! (a->IsInRing() ? (a->IsAromatic() ? "AR" : "AL") : "NO"));
OBFFLog(_logbuf);
}
}
***************
*** 855,875 ****
}
if (IsSetupNeeded(mol)) {
- int *formal_charge = new int[mol.NumAtoms()];
- int i;
-
- i = 0;
- FOR_ATOMS_OF_MOL (atom, mol) {
- formal_charge[i] = atom->GetFormalCharge();
- ++i;
- }
_mol = mol;
- i = 0;
- FOR_ATOMS_OF_MOL (atom, _mol) {
- atom->SetFormalCharge(formal_charge[i]);
- ++i;
- }
- delete [] formal_charge;
_ncoords = _mol.NumAtoms() * 3;
if (_velocityPtr)
--- 856,862 ----
***************
*** 925,945 ****
}
if (IsSetupNeeded(mol)) {
- int *formal_charge = new int[mol.NumAtoms()];
- int i;
-
- i = 0;
- FOR_ATOMS_OF_MOL (atom, mol) {
- formal_charge[i] = atom->GetFormalCharge();
- ++i;
- }
_mol = mol;
- i = 0;
- FOR_ATOMS_OF_MOL (atom, _mol) {
- atom->SetFormalCharge(formal_charge[i]);
- ++i;
- }
- delete [] formal_charge;
_ncoords = _mol.NumAtoms() * 3;
if (_velocityPtr)
--- 912,918 ----
*** include/openbabel/atom.h.orig 2012-05-18 00:20:06.932510403 +0200
--- include/openbabel/atom.h 2012-05-18 00:05:37.041386762 +0200
***************
*** 82,88 ****
protected:
unsigned char _ele; //!< atomic number (type
unsigned char to minimize space -- allows for 0..255 elements)
char _impval; //!< implicit valence
! char _type[6]; //!< atomic type
short _fcharge; //!< formal charge
unsigned short _isotope; //!< isotope (0 = most
abundant)
short _spinmultiplicity;//!< atomic spin, e.g.,
2 for radical 1 or 3 for carbene
--- 82,88 ----
protected:
unsigned char _ele; //!< atomic number (type
unsigned char to minimize space -- allows for 0..255 elements)
char _impval; //!< implicit valence
! char _type[8]; //!< atomic type
short _fcharge; //!< formal charge
unsigned short _isotope; //!< isotope (0 = most
abundant)
short _spinmultiplicity;//!< atomic spin, e.g.,
2 for radical 1 or 3 for carbene
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
OpenBabel-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss