| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 
 | .. module:: ase.calculators.socketio
===========================================
Communication with calculators over sockets
===========================================
ASE can use sockets to communicate efficiently with certain external
codes using the protocol of `i-PI <http://ipi-code.org/>`_.  This may
significantly speed up geometry optimizations, dynamics and other
algorithms in which ASE moves the atoms while the external code
calculates energies, forces, and stress.  Note that ASE does not
require i-PI, but simply uses the same protocol.
The reference article for i-PI is :doi:`Ceriotti, More, Manolopoulos, Comp. Phys. Comm. 185, 1019-1026 (2014) <10.1016/j.cpc.2013.10.027>`.
Introduction
------------
Normally, file-IO calculators in ASE launch a new process to calculate
every atomic step.  This is inefficient since the codes will need to
either start from scratch or perform significant IO between steps.
Some codes can run in "driver mode" where a server provides atomic
coordinates through a socket connection, and the code returns
energies, forces, and stress to the server.  That way the startup
overhead is eliminated, and the codes can reuse and extrapolate
wavefunctions and other quantities for increased efficiency.
ASE provides such a server in the form of a calculator.
Which codes can be used with socket I/O calculators?
----------------------------------------------------
Below is a list of codes that can run as clients, and whether ASE
provides a calculator that supports doing so.
================ =========================================
Client program   Supported by ASE calculator
================ =========================================
Abinit           Yes
ASE              Yes - ASE provides a client as well
cp2k             No; ASE uses cp2k shell instead
DFTB+            Yes
FHI-aims         Yes
GPAW             Yes, using the ASE client
Lammps           No; ASE uses lammpsrun/lammpslib instead
NWChem           Yes
Quantum Espresso Yes
Siesta           Yes
Yaff             No; there is no ASE calculator for Yaff
================ =========================================
The codes that are "not supported" by ASE can still be used as
clients, but you will need to generate the input files and launch the
client programs yourself.
Codes may require different commands, keywords, or compilation options
in order to run in driver mode.  See the code's documentation for
details.  The i-PI documentation may also be useful.
How to use the ASE socket I/O interface
---------------------------------------
The following examples should work if ASE is configured with each of the
calculators in question, and if the pseudopotentials are available.
Use ``ase info --calculators`` to see which calculators are installed
and make sure your configuration works for the calculator in question.
Then the following examples should work out of the box as long as
you adapt the specifications of pseudopotential files to match
your configuration.
.. literalinclude:: example_espresso.py
.. note::
   It is wise to ensure smooth termination of the connection.  This
   can be done by calling ``calc.close()`` at the end or, more
   elegantly, by enclosing using the ``with`` statement as done in all
   examples here.
Example using FHI-aims
.. literalinclude:: example_aims.py
Example using Siesta
.. literalinclude:: example_siesta.py
Example using DFTB+
.. literalinclude:: example_dftb.py
.. note:: The DFTB+ script did not work with INET sockets.
          This may have been a problem on the test machine.
          The relevant keyword is ``Driver_Socket_Port=<portnumber>``
          in case someone wants to test.
Example using NWChem
.. literalinclude:: example_nwchem.py
Example using Abinit
.. literalinclude:: example_abinit.py
For codes other than these, see the next section.
Run server and client manually
------------------------------
ASE can run as a client using the SocketClient class.  This may be
useful for controlling calculations remotely or using a serial process
to control a parallel one.
This example will launch a server without (necessarily) launching any client:
.. literalinclude:: example_server.py
Run it and then run the client:
.. literalinclude:: example_client_gpaw.py
This also demonstrates how to use the interface with GPAW.
Instead of running the client script, it is also possible
to run any other program that acts as a client.  This
includes the codes listed in the compatibility table above.
Module documentation
--------------------
.. autoclass:: ase.calculators.socketio.SocketIOCalculator
.. autoclass:: ase.calculators.socketio.SocketClient
The SocketServer allows launching a server without the need
to create a calculator:
.. autoclass:: ase.calculators.socketio.SocketServer
 |