Re: [Open Babel] REAL FIX: Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Paolo Tosco
> My only worry is that the (char *)to parameter passed in has to be > long enough to hold the (char*)from parameter. I assume it is. > > Craig > Clearly this was also the concern of the original author, who, to avoid any assumption, decided to use strncpy to avoid buffer overflows. Simply he/

Re: [Open Babel] REAL FIX: Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Paolo Tosco
Dear Craig, if you read more carefully my post you will see I have *perfectly* clear the difference between the size of a structure and the length of the string. Using strncpy instead of strcpy is the first rule to avoid a buffer overflow - strcpy is deprecated by all good programming practic

[Open Babel] Where can I see the tanimoto formula? (Pybel)

2012-05-17 Thread Park Hyerin
I guessed "_openbabel.so" has tanimoto formula and calculates it, but I cannot see inside of "_openbabel.so". Can I get the code of tanimoto calculate function? >From that... I want to calculate substructure coefficient. I'll be thank full for your help and kindness ;) Park. ---

Re: [Open Babel] REAL FIX: Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Craig James
Hi Paolo, I think you (and the original author) have mixed up the size of the structures with the length of the string. There's no need to do a sizeof() or to define a constant OB_ATOM_TYPE_LENGTH. Here's what I think is needed ... it's actually simpler than the original. Just use strcpy() inste

[Open Babel] REAL FIX: Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Paolo Tosco
Actually that sizeof in Translate (data.cpp) is plain wrong, since it refers to sizeof(char *) which is 8 on a 64-bit OS and 4 on a 32-bit OS; build the attached test.c with -m64 and -m32 and run to verify that: $ gcc -m64 test.c -o test64 $ ./test64 This is really 6: 6 This is machine-dependen

[Open Babel] SOLVED: Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Paolo Tosco
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

Re: [Open Babel] Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Craig James
HI Paolo, On Thu, May 17, 2012 at 11:16 AM, Paolo Tosco wrote: > I may be wrong here, but my impression is that both OBMol and OBAtom = > operators work fine, the problem is that formal charges are zeroed after > the call to Clear() in the OBMol = operator, as can ve verified printing > the res

Re: [Open Babel] Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Paolo Tosco
I may be wrong here, but my impression is that both OBMol and OBAtom = operators work fine, the problem is that formal charges are zeroed after the call to Clear() in the OBMol = operator, as can ve verified printing the results of GetFormalCharge() before and after Clear(). Therefore what OBAt

Re: [Open Babel] Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Craig James
I have narrowed down the "lost charge" problem to atomtyper.cpp. OBMol::operator= calls OBAtom::operator=, which calls the atom typer to figure out the type of the *source* atom. During that process, the atom typer erases the charge on the source atoms. I'm still digging, but I'm way beyond my ar

Re: [Open Babel] Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Craig James
Hi Paolo, On Thu, May 17, 2012 at 9:43 AM, Paolo Tosco wrote: > RIght, that's why my modification to the copy constructor fixes the issue > :-) > You are correct ... my apologies for not examining your patch more closely when you sent it. I updated to the latest from SVN and applied your patc

Re: [Open Babel] Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Craig James
On Thu, May 17, 2012 at 9:04 AM, Chris Morley wrote: > Craig's failing example works fine for me under Windows with both 2.3.1 > and the development code. As he suggested, this inconsistency suggests > that there is something not being initialized properly. The logic around > the flag OB_TCHARGE_

Re: [Open Babel] Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Paolo Tosco
Dear Chris, you are right that my patch seemingly duplicates the copying of atom formal charges which is already done in the OBAtom::Duplicate(); however, OBAtom::Duplicate() comes after Clear() has been called, so formal charges have been reset. I have verified that, and this is why my patch

Re: [Open Babel] Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Chris Morley
Craig's failing example works fine for me under Windows with both 2.3.1 and the development code. As he suggested, this inconsistency suggests that there is something not being initialized properly. The logic around the flag OB_TCHARGE_MOL is a bit tricky and so is a candidate, but I cannot see

Re: [Open Babel] Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Craig James
Here is another observation on this problem of lost charges during SDF to SMILES. The first metal ion always retains the correct charge. All the other metal ions lose their charge. Does this ring any bells? Thanks ... this problem is holding up a major project. Here's the example. Notice that

Re: [Open Babel] Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Craig James
Hi Paolo, Thanks very much for the patch. Unfortunately, the OBForceField functions that you patched are never called at all during the SDF-to-SMILES conversion process, so the patch doesn't resolve my issue. OBForceField only seems to be called if I use the --gen3D option. Best regards, Craig

Re: [Open Babel] Atom charge lost in 2.3.x SDF-to-SMILES conversion

2012-05-17 Thread Paolo Tosco
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 hav