Dear Craig,
I have faced the identical problem with MMFF94, and I have previously
submitted a similar patch which has already been applied to SVN
OpenBabel. However, now I realize that my fix had only solved my own
problem, but not a more general problem connected with formal charges.
So I have attached a much better patch, which reverts my previous one,
and instead applies it on the OBMol copy constructor, so that it becomes
of general use.
To make a long story short, if you patch the current OpenBabel SVN
version with the attached patch your issue will be solved.
From the OpenBabel root folder:
patch -p0 < patch_17-05-2012.patch
Dear Geoff, would you please apply it also to the SVN trunk so that also
other OpenBabel users may benefit from that? It also includes a small
patch on "A T O M T Y P E S" logging that I had left behind previously.
Best regards,
Paolo
On 05/17/2012 01:44 AM, Craig James wrote:
Here's another problem in 2.3.x that's not in 2.2.x. I realize these
are bogus molecules, but it illustrates a serious problem.
$ echo "[Fe+2][Fe-2].[Fe+2].[Fe-2]" | babel -i smi -o can
[Fe-2][Fe+2].[Fe-2].[Fe+2]
Everything looks good -- charges are maintained. Now go through the
SDF format:
$ echo "[Fe+2][Fe-2].[Fe+2].[Fe-2]" | babel -i smi -o sdf | babel -i
sdf -o can
[Fe+2][Fe].[Fe].[Fe]
Not so good -- charges are dropped. Where is the problem? It turns
out the SDF is correct:
$ echo "[Fe+2][Fe-2].[Fe+2].[Fe-2]" | babel -i smi -o sdf
OpenBabel05161216052D
4 1 0 0 0 0 0 0 0 0999 V2000
0.0000 0.0000 0.0000 Fe 0 2 0 0 0 0 0 0 0 0 0 0
0.0000 0.0000 0.0000 Fe 0 6 0 0 0 0 0 0 0 0 0 0
0.0000 0.0000 0.0000 Fe 0 2 0 0 0 15 0 0 0 0 0 0
0.0000 0.0000 0.0000 Fe 0 6 0 0 0 15 0 0 0 0 0 0
1 2 1 0 0 0 0
M CHG 4 1 2 2 -2 3 2 4 -2
M END
$$$$
The charges are all properly marked in the atom block and in the M CHG
line. And the "15" in atoms 3 and 4 means "zero valence" which is
right. Yet the SMILES is wrong.
It turns out this same thing happens if you use
atom->SetFormalCharge(). It sometimes works and sometimes doesn't.
Note that it works correctly in OpenBabel 2.2.x:
$ echo "[Fe+2][Fe-2].[Fe+2].[Fe-2]" | babel -i smi -o sdf | babel -i
sdf -o can
[Fe-2].[Fe-2][Fe+2].[Fe+2]
Anyone have any idea what changed, either in the OpenBabel internals
or the SMILES generator, that would affect the way charges are
interpreted?
Craig
------------------------------------------------------------------------------
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
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
--
==========================================================
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: paolo.to...@unito.it http://open3dqsar.org
==========================================================
*** src/forcefield.cpp.orig 2012-05-17 11:53:17.393007026 +0200
--- src/forcefield.cpp 2012-05-17 11:57:30.640008358 +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 ----
*** src/mol.cpp.orig 2012-05-17 11:53:45.445195944 +0200
--- src/mol.cpp 2012-05-17 11:53:55.225196004 +0200
***************
*** 1252,1257 ****
--- 1252,1263 ----
OBAtom *atom;
OBBond *bond;
+ int *formal_charge = new int[src.NumAtoms()];
+ int n = 0;
+ FOR_ATOMS_OF_MOL (atom, src) {
+ formal_charge[n] = atom->GetFormalCharge();
+ ++n;
+ }
Clear();
BeginModify();
***************
*** 1262,1267 ****
--- 1268,1278 ----
for (atom = src.BeginAtom(i);atom;atom = src.NextAtom(i))
AddAtom(*atom);
+ for (n = 0, atom = this->BeginAtom(i);atom;atom = this->NextAtom(i)) {
+ (*atom).SetFormalCharge(formal_charge[n]);
+ ++n;
+ }
+ delete [] formal_charge;
for (bond = src.BeginBond(j);bond;bond = src.NextBond(j))
AddBond(*bond);
------------------------------------------------------------------------------
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
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss