Files
rdkit/Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/MolToFromByteArray.cs
Paolo Tosco ab980bca44 SWIG pickling improvements (and other cleanup) (#6133)
* wip

* - avoid leaking memory after instantiating UChar_Vect
- fix some indentation
- make it easier to read/write pickles as native byte arrays from Java and C#
- add tests

---------

Co-authored-by: Tosco, Paolo <paolo.tosco@novartis.com>
2023-03-01 05:00:56 +01:00

30 lines
776 B
C#

// Linux:
// compile with
// mcs -platform:x64 -r:../RDKit2DotNet.dll -out:MolToFromByteArray.exe MolToFromByteArray.cs
// and run with
// LD_LIBRARY_PATH=..:$RDBASE/lib:$LD_LIBRARY_PATH MONO_PATH=.. mono MolToFromByteArray.exe
using System.IO;
using System.Diagnostics;
using GraphMolWrap;
public class MolToFromByteArrayTest
{
static void Main(string[] args)
{
string smi = "CN(C)c1ccc2c(=O)cc[nH]c2c1";
string pklFileName = "quinolone.pkl";
{
ROMol mol = RWMol.MolFromSmiles(smi);
byte[] pkl = mol.ToByteArray();
File.WriteAllBytes(pklFileName, pkl);
mol.Dispose();
}
{
byte[] pkl = File.ReadAllBytes(pklFileName);
ROMol mol = ROMol.FromByteArray(pkl);
Debug.Assert(mol.MolToSmiles() == smi);
mol.Dispose();
}
}
}