I have the same problem when using obdotnet.
The error message is 
Attempted to read or write protected memory. This is often an indication
that other memory is corrupt.
   at OpenBabel.openbabelcsharpPINVOKE.delete_OBPairData(HandleRef jarg1)
   at OpenBabel.OBPairData.Dispose()
   at OpenBabel.OBPairData.Finalize()

Thanks for Noel's solution.

Charlie


baoilleach wrote:
> 
> Hello Loris,
> 
> This problem is due to the PairData object getting destroyed by
> Python, while the C++ OBMol still wants to keep it. The solution is to
> use CloneData instead of SetData. In other words, *never* use SetData
> from Python or any other scripting language. I will update the Python
> documentation to make this clear.
> 
> You might find it useful to look at the code of pybel.py to see how I
> do things there.
> 
> Noel
> 
> On 16/09/2008, Loris Moretti <[email protected]> wrote:
>> Hi all,
>>
>>  I am quite new to OpenBabel I am trying to develop a script in Python
>> with
>>  OpenBabel. The script reads a multiple sdf file, takes a molecule per
>> time and
>>  calculates some properties. It adds the property value and attribute to
>> the
>>  OBMol object with OBPairData and then, it writes out the molecules into
>> a
>>  multiple sdf file with the new field.
>>
>>  a very simple form of the script:
>>
>>  #########################################################
>>  #!/usr/bin/python
>>
>>  import openbabel
>>
>>  obConversion = openbabel.OBConversion()
>>  obConversion.SetInAndOutFormats("sdf", "sdf")
>>
>>  mol = openbabel.OBMol()
>>
>>  iteratorMol = obConversion.ReadFile(mol, "molecules.sdf")
>>
>>  while iteratorMol:
>>
>>     newData = openbabel.OBPairData()
>>     newData.SetAttribute("NEWDATA")
>>     newData.SetValue("blabla")
>>     mol.SetData(newData)
>>
>>     print obConversion.WriteString(mol)
>>
>>     iteratorMol = obConversion.Read(mol)
>>  #########################################################
>>
>>  The script works for the first molecule of the input file but fails for
>> the
>>  others with a "segmentation fault" error.
>>  I tested it line by line and I saw there is a problem to reuse the
>> OBPairData
>>  object.
>>
>>  It might be a trivial error of mine but I cannot see it!
>>  It might be an error of the system I use!
>>
>>  Can anyone help, please.
>>
>>  Thanks in advance,
>>  loris...
>>
>> 
>> -------------------------------------------------------------------------
>>  This SF.Net email is sponsored by the Moblin Your Move Developer's
>> challenge
>>  Build the coolest Linux based applications with Moblin SDK & win great
>> prizes
>>  Grand prize is a trip for two to an Open Source event anywhere in the
>> world
>>  http://moblin-contest.org/redirect.php?banner_id=100&url=/
>>  _______________________________________________
>>  OpenBabel-scripting mailing list
>>  [email protected]
>>  https://lists.sourceforge.net/lists/listinfo/openbabel-scripting
>>
> 
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the
> world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> OpenBabel-scripting mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/openbabel-scripting
> 
> 

-- 
View this message in context: 
http://old.nabble.com/OBPairData-problem-tp19534394p26720016.html
Sent from the openbabel-scripting mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
OpenBabel-scripting mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbabel-scripting

Reply via email to