[Openchemistry-developers] RPC Listener?
Patrick Avery
psavery at buffalo.edu
Thu Apr 6 14:20:02 EDT 2017
I think I have one more major question with regard to this.
I noticed that it doesn't appear that the Avogadro2 binaries (
http://www.openchemistry.org/downloads/) were compiled with the RPC stuff
(perhaps the cmake definition Avogadro_ENABLE_RPC was set to off when they
were compiled?).
For future builds, can I request one of these two options?
1. Enable the Avogadro_ENABLE_RPC option when building.
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.
Thank you,
Patrick
On Tue, Apr 4, 2017 at 7:17 PM, Marcus D. Hanwell <
marcus.hanwell at kitware.com> wrote:
> 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.
>
> 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.
>
>
> On Tue, Apr 4, 2017 at 6:21 PM, Patrick Avery <psavery at buffalo.edu> wrote:
>
>> 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.
>>
>> Basic QJsonObject to be sent:
>> {
>> { "jsonrpc" : "2.0" },
>> { "id" : idNum }
>> }
>>
>> The other current keys are "method" and "params".
>>
>> Current options for "method":
>>
>> "openFile" - tells Avogadro2 to open a file
>> "loadMolecule" - send molecule data using any supported Avogadro2 format
>> to get Avogadro2 to set that as a new molecule
>>
>> If the method is "openFile", then "params" needs to be set like this:
>> {
>> { "fileName" : "thefilename" }
>> }
>>
>> So the overall json looks like this:
>>
>> {
>> { "jsonrpc" : "2.0" },
>> { "id" : idNum },
>> { "method" : "openFile" },
>> { "params" :
>> {
>> { "fileName" : "rutile.POSCAR" }
>> }
>> }
>> }
>>
>> If the method is "loadMolecule", then "params" needs to be set like this:
>> {
>> { "format" : "whateverFormat" },
>> { "content" : "theData" }
>> }
>>
>> So the overall json looks like this:
>>
>> {
>> { "jsonrpc" : "2.0" },
>> { "id" : idNum },
>> { "method" : "openFile" },
>> { "params" :
>> {
>> { "format" : "POSCAR" },
>> { "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" }
>> }
>> }
>> }
>>
>> With the QJsonObject type, you can initialize QJsonObjects with a
>> standard initializer like so:
>>
>> QJsonObject jsonObject {
>> { "jsonrpc", "2.0" },
>> { "id", idNum }
>> };
>>
>> Where you just use commas instead of colons.
>>
>> 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:
>> https://github.com/OpenChemistry/molequeue/blob/master
>> /molequeue/client/jsonrpcclient.cpp
>>
>> Basically, you have to connect the QLocalSocket like so:
>>
>> QLocalSocket* socket = new QLocalSocket;
>> socket->connectToServer("serverName");
>>
>> In our case, "serverName" is "avogadro".
>>
>> You can create a QDataStream with the socket and send info to the socket
>> that way.
>>
>> QDataStream stream(socket);
>> stream << jsonData;
>>
>> 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:
>>
>> connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket()));
>>
>> Right now, Avogadro just communicates back error messages (I think). But
>> we can eventually get it to send back other information too.
>>
>> On Tue, Apr 4, 2017 at 5:40 PM, Geoffrey Hutchison <
>> geoff.hutchison at gmail.com> wrote:
>>
>>> > I think I will be able to get this to work just fine. Thank you Marcus!
>>>
>>> If so, do you think you could take some notes on this? (e.g., what
>>> methods are available)
>>>
>>> Thanks,
>>> -Geoff
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/openchemistry-developers/attachments/20170406/3121f6d1/attachment.html>
More information about the Openchemistry-developers
mailing list