Handling copy and paste from Symyx Draw 3.1

User e103a02d82

04-11-2009 13:44:28

Did anyone have issues copying and pasting from symyx Draw 3.1 to Marvin.


We're getting ASCII characters 21 and 22 instead of new lines in the Molfile and SKC formats on the clipboard.


Did you see this before and how have you handled it?


Thanks Andrew

User 651c6a446c

04-11-2009 14:18:21

To provide more information to Andy's post above, what we are doing is creating a Molecule object using the the MolImporter class, and then converting it to an image using MolPrinter.


This all works fine using a Smiles code, or a mol file, but what we would like to do as well is pull the MDLCT format off the clipboard and import this. I have tried the following code -


IDataObject ido = Clipboard.GetDataObject();

string[] formats = ido.GetFormats();

MemoryStream ms = (MemoryStream) ido.GetData("MDLCT");

byte[] b = new byte[ms.Length];

ms.Read(b, 0, (int)ms.Length);

 

Molecule mol = MolImporter.importMol(b);

and I get a MolFormatException - Cannot recognize format, when it reaches the import line.


Is there any way of getting this to work please?


Thanks.

ChemAxon 5433b8e56b

04-11-2009 14:18:38

Hi Andrew!


Exactly how do you try to get data from the clipboard?


Since 5.2.1 Marvin has API to help processing clipboard data so it may can help you.


The clipboard format which is used by MDL is a little tricky, it is a C sytle String, and it does not contains any EOL characters.


Regards,
Istvan

User 651c6a446c

04-11-2009 14:36:20

Forgot to mention, but as can be seen from the code above we are using the .NET libraries.

ChemAxon 5433b8e56b

04-11-2009 14:37:05

I see.


This will be easier then. The format which is used by MDL is a simple format, but it is not recognized by default in MolImporter.


You can do two things:


- It is better in performance - i think - when you convert MDL clipboard format to MDL mol file format. It is simple since the clipboard format conatins a c style string, which contains variable length blocks. Each block is a line from the mol file format. Each block contains the length of the block in the first byte, the other bytes in the block are the byte array representation of the line. The first block is 0x00 byte because the mol file format contains an empty line as the first line.


- The other thing you can use is the Marvin API, which can makes this conversion and also uses MolImporter. In the API we have a class called ClipboardHandler. It is a static class, and it has a method called getObjectFromClipboard(boolean) it tries to retreive the data from the system clipboard in all known input clipboard format. The method returns a Java object, it can be cast to Molecule or MacroMolecule, the type of the retrieved data depends on the data represented in the clipboard. A MacroMolecule returned only in the case when the clipboard contains data in pdb format. This API class will be deprecated and moved from chemaxon.marvin.util package to chemaxon.marvin.modules.datatransfer package in Marvin 5.3, and will be redesigned at all, but this function won't be changed.


I hope this information helps. If you have further questions don't hasitate to ask.


Regards,
Istvan

User 651c6a446c

04-11-2009 14:50:03

Thankyou for your reply.


I tried using the getObjectFromClipboard call, and got a not implemented exception. However, now I understand the structure of the clipboard data I can just recreate a normal mol file from this, so will use this instead.


Thanks.

User 651c6a446c

04-11-2009 15:19:25

In case anyone else needs it in .NET -


private String ConvertMDLCTToMol(byte[] mdlct)
        {
            String result = "";

            int byteindex = 0;

            System.Text.Encoding encoding = new System.Text.ASCIIEncoding();

            while (byteindex < mdlct.Length)
            {
                //Read number of bytes contained in mdlct[byteindex].
               
int lineLength = Convert.ToInt32(mdlct[byteindex]);

                //Copy bytes for line out to separate array.
                byte[] linebytes = new byte[lineLength];
                Buffer.BlockCopy(mdlct,byteindex + 1,linebytes,0,lineLength);

                //Convert bytes to a string
                String line = encoding.GetString(linebytes);

                //Append to the result string with end of line characters.
                result += line + "\r\n";
                byteindex += lineLength + 1;               
            }

            return result;
        }

ChemAxon 5433b8e56b

04-11-2009 17:06:10

The algorithm seems similar to ours, so i think it will be good. Sorry for the desinformation about Clipboardhandler, unfortunatelly the current .net release does not suport clipboard operations at all. I do not know that before we discuss this with my collegue.


The 5.3 release, and the .Net libraries coming with it will contain clipboard support. After that i suggest you to review the refactored ClipboardHandler class, and the related classes located in chemaxon.marvin.modules.datatransfer package, it might be useful.


Regards,
Istvan