matscipy.socketcalc

Functions

pack_atoms_to_reftraj_str(at, label)

pack_atoms_to_xyz_str(at, label)

pack_results_to_reftraj_output_str(at)

unpack_reftraj_output_str_to_results(data)

unpack_reftraj_str_to_atoms(data)

unpack_xyz_str_to_results(data)

Classes

AtomsRequestHandler(request, client_address, ...)

AtomsServer

alias of AtomsServerAsync

AtomsServerAsync(server_address, ...[, ...])

Asynchronous (threaded) version of AtomsServer

AtomsServerSync(server_address, ...[, ...])

CastepClient(client_id, exe[, env, npj, ...])

Subclass of Client for running CASTEP calculations.

Client(client_id, exe[, env, npj, ppn, ...])

Represents a single Client job

QMClient(client_id, exe[, env, npj, ppn, ...])

Abstract subclass of Client for QM calculations

QUIPClient(client_id, exe[, env, npj, ppn, ...])

Subclass of Client for running QUIP calculations.

SocketCalculator(client[, ip, atoms, port, ...])

ASE-compatible calculator which communicates with remote force engines via sockets using a (synchronous) AtomsServer.

VaspClient(client_id, exe[, env, npj, ppn, ...])

Subclass of Client for running VASP calculations.

matscipy.socketcalc.pack_atoms_to_reftraj_str(at, label)
matscipy.socketcalc.pack_atoms_to_xyz_str(at, label)
matscipy.socketcalc.unpack_reftraj_str_to_atoms(data)
matscipy.socketcalc.pack_results_to_reftraj_output_str(at)
matscipy.socketcalc.unpack_reftraj_output_str_to_results(data)
matscipy.socketcalc.unpack_xyz_str_to_results(data)
class matscipy.socketcalc.AtomsRequestHandler(request, client_address, server)

Bases: StreamRequestHandler

Attributes:
timeout

Methods

finish

handle

setup

handle()
__init__(request, client_address, server)
disable_nagle_algorithm = False
finish()
rbufsize = -1
setup()
timeout = None
wbufsize = 0
class matscipy.socketcalc.AtomsServerSync(server_address, RequestHandlerClass, clients, bind_and_activate=True, max_attempts=3, bgq=False, logger=<matscipy.logger.Logger object>)

Bases: TCPServer

Attributes:
timeout

Methods

close_request(request)

Called to clean up an individual request.

fileno()

Return socket file number.

finish_request(request, client_address)

Finish one request by instantiating RequestHandlerClass.

get_request()

Get the request and client address from the socket.

handle_error(request, client_address)

Handle an error gracefully.

handle_request()

Handle one request, possibly blocking.

handle_timeout()

Called if no new request arrives within self.timeout.

process_request(request, client_address)

Call finish_request.

serve_forever([poll_interval])

Handle one request at a time until shutdown.

server_activate()

Called by constructor to activate the server.

server_bind()

Called by constructor to bind the socket.

server_close()

Called to clean-up the server.

service_actions()

Called by the serve_forever() loop.

shutdown()

Stops the serve_forever loop.

shutdown_request(request)

Called to shutdown and close an individual request.

verify_request(request, client_address)

Verify the request.

get_results

join_all

put

shutdown_clients

allow_reuse_address = True
__init__(server_address, RequestHandlerClass, clients, bind_and_activate=True, max_attempts=3, bgq=False, logger=<matscipy.logger.Logger object>)

Constructor. May be extended, do not override.

request_queue_size = 5
server_activate()

Called by constructor to activate the server.

May be overridden.

shutdown_clients()
shutdown()

Stops the serve_forever loop.

Blocks until the loop has finished. This must be called while serve_forever() is running in another thread, or it will deadlock.

put(at, client_id, label, force_restart=False)
join_all()
get_results()
address_family = 2
close_request(request)

Called to clean up an individual request.

fileno()

Return socket file number.

Interface required by selector.

finish_request(request, client_address)

Finish one request by instantiating RequestHandlerClass.

get_request()

Get the request and client address from the socket.

May be overridden.

handle_error(request, client_address)

Handle an error gracefully. May be overridden.

The default is to print a traceback and continue.

handle_request()

Handle one request, possibly blocking.

Respects self.timeout.

handle_timeout()

Called if no new request arrives within self.timeout.

Overridden by ForkingMixIn.

process_request(request, client_address)

Call finish_request.

Overridden by ForkingMixIn and ThreadingMixIn.

serve_forever(poll_interval=0.5)

Handle one request at a time until shutdown.

Polls for shutdown every poll_interval seconds. Ignores self.timeout. If you need to do periodic tasks, do them in another thread.

server_bind()

Called by constructor to bind the socket.

May be overridden.

server_close()

Called to clean-up the server.

May be overridden.

service_actions()

Called by the serve_forever() loop.

May be overridden by a subclass / Mixin to implement any code that needs to be run during the loop.

shutdown_request(request)

Called to shutdown and close an individual request.

socket_type = 1
timeout = None
verify_request(request, client_address)

Verify the request. May be overridden.

Return True if we should proceed with this request.

class matscipy.socketcalc.AtomsServerAsync(server_address, RequestHandlerClass, clients, bind_and_activate=True, max_attempts=3, bgq=False, logger=<matscipy.logger.Logger object>)

Bases: AtomsServerSync, ThreadingMixIn

Asynchronous (threaded) version of AtomsServer

Attributes:
timeout

Methods

close_request(request)

Called to clean up an individual request.

fileno()

Return socket file number.

finish_request(request, client_address)

Finish one request by instantiating RequestHandlerClass.

get_request()

Get the request and client address from the socket.

handle_error(request, client_address)

Handle an error gracefully.

handle_request()

Handle one request, possibly blocking.

handle_timeout()

Called if no new request arrives within self.timeout.

process_request(request, client_address)

Call finish_request.

process_request_thread(request, client_address)

Same as in BaseServer but as a thread.

serve_forever([poll_interval])

Handle one request at a time until shutdown.

server_activate()

Called by constructor to activate the server.

server_bind()

Called by constructor to bind the socket.

server_close()

Called to clean-up the server.

service_actions()

Called by the serve_forever() loop.

shutdown()

Stops the serve_forever loop.

shutdown_request(request)

Called to shutdown and close an individual request.

verify_request(request, client_address)

Verify the request.

get_results

join_all

put

shutdown_clients

shutdown()

Stops the serve_forever loop.

Blocks until the loop has finished. This must be called while serve_forever() is running in another thread, or it will deadlock.

shutdown_clients()
__init__(server_address, RequestHandlerClass, clients, bind_and_activate=True, max_attempts=3, bgq=False, logger=<matscipy.logger.Logger object>)

Constructor. May be extended, do not override.

address_family = 2
allow_reuse_address = True
block_on_close = True
close_request(request)

Called to clean up an individual request.

daemon_threads = False
fileno()

Return socket file number.

Interface required by selector.

finish_request(request, client_address)

Finish one request by instantiating RequestHandlerClass.

get_request()

Get the request and client address from the socket.

May be overridden.

get_results()
handle_error(request, client_address)

Handle an error gracefully. May be overridden.

The default is to print a traceback and continue.

handle_request()

Handle one request, possibly blocking.

Respects self.timeout.

handle_timeout()

Called if no new request arrives within self.timeout.

Overridden by ForkingMixIn.

join_all()
process_request(request, client_address)

Call finish_request.

Overridden by ForkingMixIn and ThreadingMixIn.

process_request_thread(request, client_address)

Same as in BaseServer but as a thread.

In addition, exception handling is done here.

put(at, client_id, label, force_restart=False)
request_queue_size = 5
serve_forever(poll_interval=0.5)

Handle one request at a time until shutdown.

Polls for shutdown every poll_interval seconds. Ignores self.timeout. If you need to do periodic tasks, do them in another thread.

server_activate()

Called by constructor to activate the server.

May be overridden.

server_bind()

Called by constructor to bind the socket.

May be overridden.

server_close()

Called to clean-up the server.

May be overridden.

service_actions()

Called by the serve_forever() loop.

May be overridden by a subclass / Mixin to implement any code that needs to be run during the loop.

shutdown_request(request)

Called to shutdown and close an individual request.

socket_type = 1
timeout = None
verify_request(request, client_address)

Verify the request. May be overridden.

Return True if we should proceed with this request.

matscipy.socketcalc.AtomsServer

alias of AtomsServerAsync

class matscipy.socketcalc.Client(client_id, exe, env=None, npj=1, ppn=1, block=None, corner=None, shape=None, jobname='socketcalc', rundir=None, fmt='REFTRAJ', parmode=None, mpirun='mpirun', mpirun_args=['-np'], logger=<matscipy.logger.Logger object>, max_pos_diff=1.0, max_cell_diff=0.001)

Bases: object

Represents a single Client job

Used by AtomsServer to start, restart and shutdown clients running on the Compute Nodes.

Methods

extra_args([label])

Return list of additional command line arguments to be passed to client

is_compatible(old_at, new_at, label)

Check if new_at and old_at are compatible.

postprocess(at, label)

Post-process results of calculation.

preprocess(at, label[, force_restart])

Prepare client for a calculation.

shutdown([block])

Request a client to shutdown.

start([label])

Start an individual client.

start_or_restart(at, label[, restart])

Start or restart a client

wait_for_shutdown()

Block until a client has shutdown.

write_input_files

__init__(client_id, exe, env=None, npj=1, ppn=1, block=None, corner=None, shape=None, jobname='socketcalc', rundir=None, fmt='REFTRAJ', parmode=None, mpirun='mpirun', mpirun_args=['-np'], logger=<matscipy.logger.Logger object>, max_pos_diff=1.0, max_cell_diff=0.001)
extra_args(label=None)

Return list of additional command line arguments to be passed to client

start(label=None)

Start an individual client.

Raises RuntimeError if this client is already running.

shutdown(block=True)

Request a client to shutdown.

If block=True, does not return until shutdown is complete. If block=False, waits for the client to shutdown in a new thread. Check self.waits_thread.isAlive() to see when shutdown has finished. (This function also returns a handle to the wait thread when block=False).

wait_for_shutdown()

Block until a client has shutdown.

Typically called automatically by shutdown() or start_or_restart().

Shutdown should previously have been initiated by queuing a ‘shutdown’ or ‘restart’ request. Waits CLIENT_TIMEOUT for graceful shutdown. If client is still alive, a SIGTERM signal is sent. If this has had no effect after a further CLIENT_TIMEOUT, then a SIGKILL is sent. Does not return until the SIGKILL has taken effect.

This function also marks shutdown task as complete in servers’s input_q for this client.

start_or_restart(at, label, restart=False)

Start or restart a client

If restart=True, wait for previous client to shutdown first. Calls write_input_files() followed by start().

preprocess(at, label, force_restart=False)

Prepare client for a calculation.

Starts client if this is the first task for it, or schedules a restart if new configuration is not compatible with the last one submitted to the queue (see is_compatible() method).

Many be extended in subclasses to e.g. sort the atoms by atomic number. If Atoms object needs to be changed, a copy should be returned rather than updating it inplace.

Returns (at, first_time).

postprocess(at, label)

Post-process results of calculation.

May be overrriden in subclasses to e.g. reverse sort order applied in preprocess().

is_compatible(old_at, new_at, label)

Check if new_at and old_at are compatible.

Returns True if calculation can be continued, or False if client must be restarted before it can process new_at.

write_input_files(at, label)
class matscipy.socketcalc.QUIPClient(client_id, exe, env=None, npj=1, ppn=1, block=None, corner=None, shape=None, jobname='socketcalc', rundir=None, fmt='REFTRAJ', parmode=None, mpirun='mpirun', mpirun_args=['-np'], logger=<matscipy.logger.Logger object>, max_pos_diff=1.0, max_cell_diff=0.001, param_files=None)

Bases: Client

Subclass of Client for running QUIP calculations.

Initial input files are written in extended XYZ format, and subsequent communication is via sockets, in either REFTRAJ or XYZ format.

Methods

extra_args([label])

Return list of additional command line arguments to be passed to client

is_compatible(old_at, new_at, label)

Check if new_at and old_at are compatible.

postprocess(at, label)

Post-process results of calculation.

preprocess(at, label[, force_restart])

Prepare client for a calculation.

shutdown([block])

Request a client to shutdown.

start([label])

Start an individual client.

start_or_restart(at, label[, restart])

Start or restart a client

wait_for_shutdown()

Block until a client has shutdown.

write_input_files

__init__(client_id, exe, env=None, npj=1, ppn=1, block=None, corner=None, shape=None, jobname='socketcalc', rundir=None, fmt='REFTRAJ', parmode=None, mpirun='mpirun', mpirun_args=['-np'], logger=<matscipy.logger.Logger object>, max_pos_diff=1.0, max_cell_diff=0.001, param_files=None)
write_input_files(at, label)
extra_args(label=None)

Return list of additional command line arguments to be passed to client

is_compatible(old_at, new_at, label)

Check if new_at and old_at are compatible.

Returns True if calculation can be continued, or False if client must be restarted before it can process new_at.

postprocess(at, label)

Post-process results of calculation.

May be overrriden in subclasses to e.g. reverse sort order applied in preprocess().

preprocess(at, label, force_restart=False)

Prepare client for a calculation.

Starts client if this is the first task for it, or schedules a restart if new configuration is not compatible with the last one submitted to the queue (see is_compatible() method).

Many be extended in subclasses to e.g. sort the atoms by atomic number. If Atoms object needs to be changed, a copy should be returned rather than updating it inplace.

Returns (at, first_time).

shutdown(block=True)

Request a client to shutdown.

If block=True, does not return until shutdown is complete. If block=False, waits for the client to shutdown in a new thread. Check self.waits_thread.isAlive() to see when shutdown has finished. (This function also returns a handle to the wait thread when block=False).

start(label=None)

Start an individual client.

Raises RuntimeError if this client is already running.

start_or_restart(at, label, restart=False)

Start or restart a client

If restart=True, wait for previous client to shutdown first. Calls write_input_files() followed by start().

wait_for_shutdown()

Block until a client has shutdown.

Typically called automatically by shutdown() or start_or_restart().

Shutdown should previously have been initiated by queuing a ‘shutdown’ or ‘restart’ request. Waits CLIENT_TIMEOUT for graceful shutdown. If client is still alive, a SIGTERM signal is sent. If this has had no effect after a further CLIENT_TIMEOUT, then a SIGKILL is sent. Does not return until the SIGKILL has taken effect.

This function also marks shutdown task as complete in servers’s input_q for this client.

class matscipy.socketcalc.QMClient(client_id, exe, env=None, npj=1, ppn=1, block=None, corner=None, shape=None, jobname='socketcalc', rundir=None, fmt='REFTRAJ', parmode=None, mpirun='mpirun', mpirun_args=['-np'], logger=<matscipy.logger.Logger object>, max_pos_diff=1.0, max_cell_diff=0.001)

Bases: Client

Abstract subclass of Client for QM calculations

Methods

extra_args([label])

Return list of additional command line arguments to be passed to client

is_compatible(old_at, new_at, label)

Check if new_at and old_at are compatible.

postprocess(at, label)

Post-process results of calculation.

preprocess(at, label[, force_restart])

Prepare client for a calculation.

shutdown([block])

Request a client to shutdown.

start([label])

Start an individual client.

start_or_restart(at, label[, restart])

Start or restart a client

wait_for_shutdown()

Block until a client has shutdown.

write_input_files

is_compatible(old_at, new_at, label)

Check if new_at and old_at are compatible.

Returns True if calculation can be continued, or False if client must be restarted before it can process new_at.

__init__(client_id, exe, env=None, npj=1, ppn=1, block=None, corner=None, shape=None, jobname='socketcalc', rundir=None, fmt='REFTRAJ', parmode=None, mpirun='mpirun', mpirun_args=['-np'], logger=<matscipy.logger.Logger object>, max_pos_diff=1.0, max_cell_diff=0.001)
extra_args(label=None)

Return list of additional command line arguments to be passed to client

postprocess(at, label)

Post-process results of calculation.

May be overrriden in subclasses to e.g. reverse sort order applied in preprocess().

preprocess(at, label, force_restart=False)

Prepare client for a calculation.

Starts client if this is the first task for it, or schedules a restart if new configuration is not compatible with the last one submitted to the queue (see is_compatible() method).

Many be extended in subclasses to e.g. sort the atoms by atomic number. If Atoms object needs to be changed, a copy should be returned rather than updating it inplace.

Returns (at, first_time).

shutdown(block=True)

Request a client to shutdown.

If block=True, does not return until shutdown is complete. If block=False, waits for the client to shutdown in a new thread. Check self.waits_thread.isAlive() to see when shutdown has finished. (This function also returns a handle to the wait thread when block=False).

start(label=None)

Start an individual client.

Raises RuntimeError if this client is already running.

start_or_restart(at, label, restart=False)

Start or restart a client

If restart=True, wait for previous client to shutdown first. Calls write_input_files() followed by start().

wait_for_shutdown()

Block until a client has shutdown.

Typically called automatically by shutdown() or start_or_restart().

Shutdown should previously have been initiated by queuing a ‘shutdown’ or ‘restart’ request. Waits CLIENT_TIMEOUT for graceful shutdown. If client is still alive, a SIGTERM signal is sent. If this has had no effect after a further CLIENT_TIMEOUT, then a SIGKILL is sent. Does not return until the SIGKILL has taken effect.

This function also marks shutdown task as complete in servers’s input_q for this client.

write_input_files(at, label)
class matscipy.socketcalc.VaspClient(client_id, exe, env=None, npj=1, ppn=1, block=None, corner=None, shape=None, jobname='socketcalc', rundir=None, fmt='REFTRAJ', parmode=None, mpirun='mpirun', mpirun_args=['-np'], logger=<matscipy.logger.Logger object>, max_pos_diff=1.0, max_cell_diff=0.001, **vasp_args)

Bases: QMClient

Subclass of Client for running VASP calculations.

Initial input files are written in POSCAR, INCAR, POTCAR and KPOINTS formats, and subsequent communicatin is via sockets in REFTRAJ format.

Methods

extra_args([label])

Return list of additional command line arguments to be passed to client

is_compatible(old_at, new_at, label)

Check if new_at and old_at are compatible.

postprocess(at, label)

Post-process results of calculation.

preprocess(at, label[, force_restart])

Prepare client for a calculation.

shutdown([block])

Request a client to shutdown.

start([label])

Start an individual client.

start_or_restart(at, label[, restart])

Start or restart a client

wait_for_shutdown()

Block until a client has shutdown.

write_input_files

__init__(client_id, exe, env=None, npj=1, ppn=1, block=None, corner=None, shape=None, jobname='socketcalc', rundir=None, fmt='REFTRAJ', parmode=None, mpirun='mpirun', mpirun_args=['-np'], logger=<matscipy.logger.Logger object>, max_pos_diff=1.0, max_cell_diff=0.001, **vasp_args)
preprocess(at, label, force_restart=False)

Prepare client for a calculation.

Starts client if this is the first task for it, or schedules a restart if new configuration is not compatible with the last one submitted to the queue (see is_compatible() method).

Many be extended in subclasses to e.g. sort the atoms by atomic number. If Atoms object needs to be changed, a copy should be returned rather than updating it inplace.

Returns (at, first_time).

postprocess(at, label)

Post-process results of calculation.

May be overrriden in subclasses to e.g. reverse sort order applied in preprocess().

write_input_files(at, label)
extra_args(label=None)

Return list of additional command line arguments to be passed to client

is_compatible(old_at, new_at, label)

Check if new_at and old_at are compatible.

Returns True if calculation can be continued, or False if client must be restarted before it can process new_at.

shutdown(block=True)

Request a client to shutdown.

If block=True, does not return until shutdown is complete. If block=False, waits for the client to shutdown in a new thread. Check self.waits_thread.isAlive() to see when shutdown has finished. (This function also returns a handle to the wait thread when block=False).

start(label=None)

Start an individual client.

Raises RuntimeError if this client is already running.

start_or_restart(at, label, restart=False)

Start or restart a client

If restart=True, wait for previous client to shutdown first. Calls write_input_files() followed by start().

wait_for_shutdown()

Block until a client has shutdown.

Typically called automatically by shutdown() or start_or_restart().

Shutdown should previously have been initiated by queuing a ‘shutdown’ or ‘restart’ request. Waits CLIENT_TIMEOUT for graceful shutdown. If client is still alive, a SIGTERM signal is sent. If this has had no effect after a further CLIENT_TIMEOUT, then a SIGKILL is sent. Does not return until the SIGKILL has taken effect.

This function also marks shutdown task as complete in servers’s input_q for this client.

class matscipy.socketcalc.CastepClient(client_id, exe, env=None, npj=1, ppn=1, block=None, corner=None, shape=None, jobname='socketcalc', rundir=None, fmt='REFTRAJ', parmode=None, mpirun='mpirun', mpirun_args=['-np'], logger=<matscipy.logger.Logger object>, max_pos_diff=1.0, max_cell_diff=1.0, **castep_args)

Bases: QMClient

Subclass of Client for running CASTEP calculations.

Initial input files are written in .cell and .param formats, and subsequent communication is via sockets in REFTRAJ format.

Methods

extra_args([label])

Return list of additional command line arguments to be passed to client

is_compatible(old_at, new_at, label)

Check if new_at and old_at are compatible.

postprocess(at, label)

Post-process results of calculation.

preprocess(at, label[, force_restart])

Prepare client for a calculation.

shutdown([block])

Request a client to shutdown.

start([label])

Start an individual client.

start_or_restart(at, label[, restart])

Start or restart a client

wait_for_shutdown()

Block until a client has shutdown.

write_input_files

__init__(client_id, exe, env=None, npj=1, ppn=1, block=None, corner=None, shape=None, jobname='socketcalc', rundir=None, fmt='REFTRAJ', parmode=None, mpirun='mpirun', mpirun_args=['-np'], logger=<matscipy.logger.Logger object>, max_pos_diff=1.0, max_cell_diff=1.0, **castep_args)
preprocess(at, label, force_restart=False)

Prepare client for a calculation.

Starts client if this is the first task for it, or schedules a restart if new configuration is not compatible with the last one submitted to the queue (see is_compatible() method).

Many be extended in subclasses to e.g. sort the atoms by atomic number. If Atoms object needs to be changed, a copy should be returned rather than updating it inplace.

Returns (at, first_time).

postprocess(at, label)

Post-process results of calculation.

May be overrriden in subclasses to e.g. reverse sort order applied in preprocess().

write_input_files(at, label)
extra_args(label=None)

Return list of additional command line arguments to be passed to client

is_compatible(old_at, new_at, label)

Check if new_at and old_at are compatible.

Returns True if calculation can be continued, or False if client must be restarted before it can process new_at.

shutdown(block=True)

Request a client to shutdown.

If block=True, does not return until shutdown is complete. If block=False, waits for the client to shutdown in a new thread. Check self.waits_thread.isAlive() to see when shutdown has finished. (This function also returns a handle to the wait thread when block=False).

start(label=None)

Start an individual client.

Raises RuntimeError if this client is already running.

start_or_restart(at, label, restart=False)

Start or restart a client

If restart=True, wait for previous client to shutdown first. Calls write_input_files() followed by start().

wait_for_shutdown()

Block until a client has shutdown.

Typically called automatically by shutdown() or start_or_restart().

Shutdown should previously have been initiated by queuing a ‘shutdown’ or ‘restart’ request. Waits CLIENT_TIMEOUT for graceful shutdown. If client is still alive, a SIGTERM signal is sent. If this has had no effect after a further CLIENT_TIMEOUT, then a SIGKILL is sent. Does not return until the SIGKILL has taken effect.

This function also marks shutdown task as complete in servers’s input_q for this client.

class matscipy.socketcalc.SocketCalculator(client, ip=None, atoms=None, port=0, logger=<matscipy.logger.Logger object>, bgq=False)

Bases: Calculator

ASE-compatible calculator which communicates with remote force engines via sockets using a (synchronous) AtomsServer.

Attributes:
directory
label

Methods

band_structure()

Create band-structure object for plotting.

calculate(atoms, properties, system_changes)

Do the calculation.

calculate_numerical_forces(atoms[, d])

Calculate numerical forces using finite difference.

calculate_numerical_stress(atoms[, d, voigt])

Calculate numerical stress using finite difference.

calculate_properties(atoms, properties)

This method is experimental; currently for internal use.

check_state(atoms[, tol])

Check for any system changes since last calculation.

get_magnetic_moments([atoms])

Calculate magnetic moments projected onto atoms.

get_property(name[, atoms, allow_calculation])

Get the named property.

get_stresses([atoms])

the calculator should return intensive stresses, i.e., such that stresses.sum(axis=0) == stress

read(label)

Read atoms, parameters and calculated properties from output file.

reset()

Clear all information from old calculation.

set(**kwargs)

Set parameters like set(key1=value1, key2=value2, ...).

set_label(label)

Set label and convert label to directory and prefix.

calculation_required

export_properties

get_atoms

get_charges

get_default_parameters

get_dipole_moment

get_forces

get_magnetic_moment

get_potential_energies

get_potential_energy

get_stress

read_atoms

shutdown

todict

implemented_properties: List[str] = ['energy', 'forces', 'stress']

Properties calculator can handle (energy, forces, …)

default_parameters: Dict[str, Any] = {}

Default parameters

name = 'SocketCalculator'
__init__(client, ip=None, atoms=None, port=0, logger=<matscipy.logger.Logger object>, bgq=False)

Basic calculator implementation.

restart: str

Prefix for restart file. May contain a directory. Default is None: don’t restart.

ignore_bad_restart_file: bool

Deprecated, please do not use. Passing more than one positional argument to Calculator() is deprecated and will stop working in the future. Ignore broken or missing restart file. By default, it is an error if the restart file is missing or broken.

directory: str or PurePath

Working directory in which to read and write files and perform calculations.

label: str

Name used for all files. Not supported by all calculators. May contain a directory, but please use the directory parameter for that instead.

atoms: Atoms object

Optional Atoms object to which the calculator will be attached. When restarting, atoms will get its positions and unit-cell updated from file.

calculate(atoms, properties, system_changes)

Do the calculation.

properties: list of str

List of what needs to be calculated. Can be any combination of ‘energy’, ‘forces’, ‘stress’, ‘dipole’, ‘charges’, ‘magmom’ and ‘magmoms’.

system_changes: list of str

List of what has changed since last calculation. Can be any combination of these six: ‘positions’, ‘numbers’, ‘cell’, ‘pbc’, ‘initial_charges’ and ‘initial_magmoms’.

Subclasses need to implement this, but can ignore properties and system_changes if they want. Calculated properties should be inserted into results dictionary like shown in this dummy example:

self.results = {'energy': 0.0,
                'forces': np.zeros((len(atoms), 3)),
                'stress': np.zeros(6),
                'dipole': np.zeros(3),
                'charges': np.zeros(len(atoms)),
                'magmom': 0.0,
                'magmoms': np.zeros(len(atoms))}

The subclass implementation should first call this implementation to set the atoms attribute and create any missing directories.

band_structure()

Create band-structure object for plotting.

calculate_numerical_forces(atoms, d=0.001)

Calculate numerical forces using finite difference.

All atoms will be displaced by +d and -d in all directions.

calculate_numerical_stress(atoms, d=1e-06, voigt=True)

Calculate numerical stress using finite difference.

calculate_properties(atoms, properties)

This method is experimental; currently for internal use.

calculation_required(atoms, properties)
check_state(atoms, tol=1e-15)

Check for any system changes since last calculation.

property directory: str
discard_results_on_any_change = False

Whether we purge the results following any change in the set() method.

export_properties()
get_atoms()
get_charges(atoms=None)
get_default_parameters()
get_dipole_moment(atoms=None)
get_forces(atoms=None)
get_magnetic_moment(atoms=None)
get_magnetic_moments(atoms=None)

Calculate magnetic moments projected onto atoms.

get_potential_energies(atoms=None)
get_potential_energy(atoms=None, force_consistent=False)
get_property(name, atoms=None, allow_calculation=True)

Get the named property.

get_stress(atoms=None)
get_stresses(atoms=None)

the calculator should return intensive stresses, i.e., such that stresses.sum(axis=0) == stress

ignored_changes: Set[str] = {}

Properties of Atoms which we ignore for the purposes of cache

property label
read(label)

Read atoms, parameters and calculated properties from output file.

Read result from self.label file. Raise ReadError if the file is not there. If the file is corrupted or contains an error message from the calculation, a ReadError should also be raised. In case of succes, these attributes must set:

atoms: Atoms object

The state of the atoms from last calculation.

parameters: Parameters object

The parameter dictionary.

results: dict

Calculated properties like energy and forces.

The FileIOCalculator.read() method will typically read atoms and parameters and get the results dict by calling the read_results() method.

classmethod read_atoms(restart, **kwargs)
reset()

Clear all information from old calculation.

set(**kwargs)

Set parameters like set(key1=value1, key2=value2, …).

A dictionary containing the parameters that have been changed is returned.

Subclasses must implement a set() method that will look at the chaneged parameters and decide if a call to reset() is needed. If the changed parameters are harmless, like a change in verbosity, then there is no need to call reset().

The special keyword ‘parameters’ can be used to read parameters from a file.

set_label(label)

Set label and convert label to directory and prefix.

Examples:

  • label=’abc’: (directory=’.’, prefix=’abc’)

  • label=’dir1/abc’: (directory=’dir1’, prefix=’abc’)

  • label=None: (directory=’.’, prefix=None)

shutdown()
todict(skip_default=True)