Binary Data Issue

User 82b20b535e

28-07-2015 14:30:05

I am successfully able to retrieve String data of the structure from the Database ( SQl Server ).


But when I try to retrieve Binary data , it returns null. Not sure what the issue is.


JChem.NET 15.6.2200


below is the Code 


returns Null data


JChemDBMolecule.Representations.Represent(MoleculeFormat.MRV).BinaryData; 


 


returns string representation


JChemDBMolecule.Representations.Represent(MoleculeFormat.MRV).StringData


Thanks

ChemAxon 2e7d8629fa

28-07-2015 21:10:54

 Hi,


 


MRV is a string-based (XML) molecule format so you can get the string representation of the structure only. When you try to get the binary representation the result is null (exception doesn't occur).


Binary molecule formats are e.g. SKC, CDX. It should work:


byte[] molData = JChemDBMolecule.Representations.Represent(MoleculeFormat.SKC).BinaryData;


molData won't be null.


 


You can get the string molecule data like this:


JChemDBMolecule.MoleculeData.StringData


In this case you can get the original molecule representation. E.g. if you store SMILES strings in your database then the result will be the SMILES string. You don't need to convert the structures to MRV format.


 


What is your workflow? What would you like to do with the binary data? Which format do you use in your DB?


 


Regards,


Gergely



User 82b20b535e

29-07-2015 12:41:29

I have started to use the MRV format to store in the DB.  I need the BinaryData for a different project and data was null. It is very confusing as I do not see any documentation outlining what you indicated below.


So your suggestion is , instead of retrieving the MRV format from DB retrieve the SKC format to get the binary representation. Let me know if i am wrong?


 


Workflow I have is I need to retrieve the structure Image in the byte[] in order to display them on the ASP page ( not a MVC project ).




Thanks

ChemAxon 2e7d8629fa

29-07-2015 13:32:52

 Hi,


 


Do not convert MRV data to SKC! SKC is a standard of the MDL Inc.:


https://en.wikipedia.org/wiki/ISIS/Draw


That was just an example for the binary stored data. SKC is a binary data itself (not a readable, string-based format). But if you use ChemAxon platform and work with MRV data that is a bad practice to convert MRV to SKC. You can loss data and it can be a slow process. Do not do that! (CDX is the same.)


If I understand correctly you need the binary representation of the MRV string. It is only a string -> binary "conversion". Like these:


System.Text.Encoding.UTF8.GetBytes(mrvString)


System.Text.Encoding.Unicode.GetBytes(mrvString)


System.Text.Encoding.ASCII.GetBytes(mrvString)


You have to specify the encoding.


 


What kind of data does the "different project" need? Can you give me some details about that? It can help. Maybe the MRV -> binary "conversion" won't be enough. What is the required input of that application? Does that know MRV format?


 


Anyway, I'm not familiar with molecule storing in databases but I can imagine you can choose better format than MRV. As I mentioned MRV is an XML what can be ineffective using RDBMS. Structure formats SMILES, SMARTS or CXSMILES, CXSMARTS can be more effective. If you have questions related this topic JChem Base Team can help you.


 


Regards,


Gergely

ChemAxon 2e7d8629fa

29-07-2015 13:44:12

 


I'm really sorry I did not notice the essential part of your response:


"Workflow I have is I need to retrieve the structure Image in the byte[] in order to display them on the ASP page"


 


You can render a JChemDBMolecule easily:


JChemDBMolecule.Renderer.RenderToBinary(ImageFormat.Emf)   // PNG, BMP, JPEG, etc.


 


You can use the following methods as well:


- RenderToImage


- RenderToStream


- RenderToFile


 


You can find some examples here:


https://www.chemaxon.com/dotNET/6.3/examples.html#rendering


 


Regards,


Gergely



User 82b20b535e

29-07-2015 13:46:02

Hi,


Thanks for a quick response and being clear of the issue. 


Since you have brought the question of ineffective using RDBMS, I would like to educated as I would like to do right thing / job. Chemist draws the chemical structure and save those in the SQL Server. 


Below is the workflow to save. Please correct me if I am wrong any where



  1. First step, Create molecule using MRV format.  IJChemMolecule savemolecule = MainFactory.Chemistry.CreateMolecule(savemodel.Structure, MoleculeFormat.MRV);

  2. Make a SQL DB Connection  IJChemDatabaseHandler database = MainFactory.Database.OpenJChem(connection);

  3. Insert or Update the Data  Table.Insert(molecule);


May i request to please suggest which format (SMILES, SMARTS or CXSMILES, CXSMARTS ) should I have to use for more effectives in SQL Server DB


Please suggest?


Thanks

User 82b20b535e

29-07-2015 13:49:51










gkovacs wrote:

 


I'm really sorry I did not notice the essential part of your response:


"Workflow I have is I need to retrieve the structure Image in the byte[] in order to display them on the ASP page"


 


You can render a JChemDBMolecule easily:


JChemDBMolecule.Renderer.RenderToBinary(ImageFormat.Emf)   // PNG, BMP, JPEG, etc.


 


You can use the following methods as well:


- RenderToImage


- RenderToStream


- RenderToFile


 


You can find some examples here:


https://www.chemaxon.com/dotNET/6.3/examples.html#rendering


 


Regards,


Gergely





Thank you for your response. I did resolve the issue but wanted a confirmation.


Below is what i am doing



This solve the issue. But please reply back to my other question on effectiveness of storing...

ChemAxon 2e7d8629fa

29-07-2015 14:15:51

1.) Rendering:


You don't need to cast JChemDBMolecule to IJChemMolecule for rendering. You can call function RenderToBinary() on JChemDBMolecule directly. It should work. But the steps are OK what you described, your code snippet has to work correctly.


 


2.) Molecule data storing in databases:


For these kind of questions please contant JChem Base Team: jcb-support _at_ chemaxon.com


 


Regards,


Gergely

ChemAxon 2e7d8629fa

29-07-2015 14:42:38

I talked to JCemBase Team about the data storing issue. If you used JChem tools, especially JChem Manager for creating structure table in your DB you don't need to change anything. In this case MRV is a good (best) choice.


So as I can see now your DB configuration is correct and the code what you use is also perfect.


Sorry for the misunderstanding.


Regards,


Gergely

User 82b20b535e

29-07-2015 15:10:40










gkovacs wrote:

I talked to JCemBase Team about the data storing issue. If you used JChem tools, especially JChem Manager for creating structure table in your DB you don't need to change anything. In this case MRV is a good (best) choice.


So as I can see now your DB configuration is correct and the code what you use is also perfect.


Sorry for the misunderstanding.


Regards,


Gergely



Hi Gergely,


Thanks for your quick response and clarifying. Structure table was created by JChemManager. 


I am happy that I have not written something bad and please do not sorry.


This helped me to re validate that legacy code I have replaced is in right direction.


Thanks