<div dir="ltr">I think I have one more major question with regard to this.<div><br></div><div>I noticed that it doesn't appear that the Avogadro2 binaries (<a href="http://www.openchemistry.org/downloads/">http://www.openchemistry.org/downloads/</a>) were compiled with the RPC stuff (perhaps the cmake definition Avogadro_ENABLE_RPC was set to off when they were compiled?).</div><div><br></div><div>For future builds, can I request one of these two options?</div><div><br></div><div>1. Enable the Avogadro_ENABLE_RPC option when building.</div><div>2. Still compile the RPC stuff, but set up a way for the user to turn on or off the RPC features via the Avogadro2 menu options. I'd be willing to help write code to make this work if this would be the route we would take.</div><div><br></div><div>Thank you,</div><div>Patrick</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 4, 2017 at 7:17 PM, Marcus D. Hanwell <span dir="ltr"><<a href="mailto:marcus.hanwell@kitware.com" target="_blank">marcus.hanwell@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">It is an implementation of JSON RPC 2.0, using the Qt JSON classes to communicate, we have some Python examples somewhere, but I think we ended up using  a different transport with MoleQueue due to Windows having no Python local socket abstraction.</div><div class="gmail_extra"><br></div><div class="gmail_extra">It is a simple RPC transport, the communication with MoleQueue was the first thing we wrote, and then we extended Avogadro to simply show molecules from MongoChem. This is implemented largely in one class right now in Avogadro 2.<div><div class="h5"><br>
<br><div class="gmail_quote">On Tue, Apr 4, 2017 at 6:21 PM, Patrick Avery <span dir="ltr"><<a href="mailto:psavery@buffalo.edu" target="_blank">psavery@buffalo.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Here's a rundown of what I've learned and how to use it. It is used more extensively in MoleQueue. Right now, in Avogadro2, it looks like you can do two things: tell it to open a file, and send it a molecule in a byte stream for it to read and load.</div><div><br></div><div>Basic QJsonObject to be sent:</div><div>{</div><div>  { "jsonrpc" : "2.0" },</div><div>  { "id" : idNum }</div><div>}</div><div><br></div><div>The other current keys are "method" and "params".</div><div><br></div><div>Current options for "method":</div><div><br></div><div>"openFile" - tells Avogadro2 to open a file</div><div>"loadMolecule" - send molecule data using any supported Avogadro2 format to get Avogadro2 to set that as a new molecule<br></div><div><br></div><div>If the method is "openFile", then "params" needs to be set like this:</div><div>{</div><div>  { "fileName" : "thefilename" }</div><div>}</div><div><br></div><div>So the overall json looks like this:</div><div><br></div><div><div>{</div><div>  { "jsonrpc" : "2.0" },</div><div>  { "id" : idNum },</div><div>  { "method" : "openFile" },</div><div>  { "params" : </div><div>    {</div><div>      { "fileName" : "rutile.POSCAR" }</div><div>    }</div><div>  }</div><div>}</div></div><div><br></div><div>If the method is "loadMolecule", then "params" needs to be set like this:</div><div>{</div><div>  { "format" : "whateverFormat" },</div><div>  { "content" : "theData" }</div><div>}</div><div><br></div><div>So the overall json looks like this:</div><div><br></div><div><div>{</div><div>  { "jsonrpc" : "2.0" },</div><div>  { "id" : idNum },</div><div>  { "method" : "openFile" },</div><div>  { "params" : </div><div>    {</div><div>      { "format" : "POSCAR" },</div><div>      { "content" : "TiO2 rutile\n1.00000000\n2.95812000   0.00000000   0.00000000\n0.00000000   4.59373000   0.00000000\n0.00000000   0.00000000   4.59373000\nO   Ti\n4   2\nDirect\n0.00000000  0.30530000  0.30530000\n0.00000000  0.69470000  0.69470000\n0.50000000  0.19470000  0.80530000\n0.50000000  0.80530000  0.19470000\n0.00000000  0.00000000  0.00000000\n0.50000000  0.50000000  0.50000000" }</div><div>    }</div><div>  }</div><div>}</div></div><div><br></div><div>With the QJsonObject type, you can initialize QJsonObjects with a standard initializer like so:</div><div><br></div><div>QJsonObject jsonObject {</div><div>  { "jsonrpc", "2.0" },</div><div>  { "id", idNum }</div><div>};</div><div><br></div><div>Where you just use commas instead of colons.</div><div><br></div><div>To send and receive the data to the RPC, you need to use a QLocalSocket object, and you can follow methods in this class here: <a href="https://github.com/OpenChemistry/molequeue/blob/master/molequeue/client/jsonrpcclient.cpp" target="_blank">https://github.com/OpenC<wbr>hemistry/molequeue/blob/master<wbr>/molequeue/client/jsonrpcclien<wbr>t.cpp</a></div><div><br></div><div>Basically, you have to connect the QLocalSocket like so: </div><div><br></div><div>QLocalSocket* socket = new QLocalSocket;</div><div>socket->connectToServer("serve<wbr>rName");</div><div><br></div><div>In our case, "serverName" is "avogadro".</div><div><br></div><div>You can create a QDataStream with the socket and send info to the socket that way.</div><div><br></div><div>QDataStream stream(socket);</div><div>stream << jsonData;</div><div><br></div><div>When you receive a signal back from the RPC server, the local socket will emit readyRead(), so if your class is a QObject, you can connect to it like so:</div><div><br></div><div> connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket()));<br></div><div><br></div><div>Right now, Avogadro just communicates back error messages (I think). But we can eventually get it to send back other information too.</div></div><div class="m_-4656147745226856272HOEnZb"><div class="m_-4656147745226856272h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 4, 2017 at 5:40 PM, Geoffrey Hutchison <span dir="ltr"><<a href="mailto:geoff.hutchison@gmail.com" target="_blank">geoff.hutchison@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>> I think I will be able to get this to work just fine. Thank you Marcus!<br>
<br>
</span>If so, do you think you could take some notes on this? (e.g., what methods are available)<br>
<br>
Thanks,<br>
-Geoff</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>