Skip to main content

A general reader/writer for CASTEP inputs

Project description

A simple CASTEP input files parser/writer

This package provide a basic framework for read/write input files of CASTEP. There is already a excellent reader/writer implemented in ase but they are ortentated to work with the Atoms and Calculator classes in ase. It also requires a CASTEP binary to exist to work. This package aim to provide a more generic framework with minimum dependency for simple (but important) tasks of writing and reading inputs files of CASTEP.

Usage

The two classes to be used for reading/writing inputs are ParamInput and CellInput. Keyword-value pairs can be set the same as dictionaries. For example:

from castepinput import CellInput, ParamInput, Block
# ParamInput is in fact just a subclass of OrderedDict
param = ParamInput(cut_off_energy=300, task="singlepoint")
param["opt_strategy"] = "speed"

# Use the Block class to signal that it is a BLOCK
# The following line sets the positions_abs
cell = CellInput(positions_abs=Block(["C 0 0 0", "C 1 0 0"])

The two classes use simple string formatting when writing out the content. See the following code as example.

cell = CellInput(snap_to_symmetry=True)

# Should give 'snap_to_symmetry : True'
cell.get_string()

# Should give 'symmetry_genreate : true'
cell['snap_to_symmetry'] = 'true'
cell.get_string()

# Not all CASTEP keyword requires a value
# Use "" as the value will result just a keyword on a line
cell['symmetry_generate'] = ''
# Should give a string with a line 'symmetry_generate'
cell.get_string()

# Set cell and positions use the set methods
cell.set_cell([10 ,10 , 10])
cell.set_positions(["O", "O"], [[0, 0, 0], [1.4, 0, 0]])
# Save to file
cell.save("O2.cell")

To initialize from a existing param/cell file, use the ParamInput.from_file method.

cell = CellInput.from_file("O2.cell")
# This should give [[10, 0, 0], [0, 10, 0], [0, 0, 10]]
cell.get_cell()

# The value returned should be "" to be consistent with setting
cell["symmetry_generate"]

We also try to be smart and convert string into python types where it is possible. Supported types are integer, floats and 1-d arrays made of integer/floats. These coversions can be avoided by using ParamInput.from_file(filename, plain=True) when loading files.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

castepinput-0.1.5.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

castepinput-0.1.5-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file castepinput-0.1.5.tar.gz.

File metadata

  • Download URL: castepinput-0.1.5.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.1.3.post20200325 requests-toolbelt/0.8.0 tqdm/4.44.1 CPython/3.8.2

File hashes

Hashes for castepinput-0.1.5.tar.gz
Algorithm Hash digest
SHA256 a364276c502f68dc1f1ae9f1a33bd77e973a4cde2e9969db8b20029640e2b4a8
MD5 0a2bac912020b7f19a8ce0d0cc02d675
BLAKE2b-256 d7c73d97671b5e893653b364bae3ab78e75b3a10bbdb4ed45eabea27a3b9b13e

See more details on using hashes here.

File details

Details for the file castepinput-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: castepinput-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.1.3.post20200325 requests-toolbelt/0.8.0 tqdm/4.44.1 CPython/3.8.2

File hashes

Hashes for castepinput-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 771cec0eeb497a1fa7038295a1eae30e97efb4a8a92e40999744162d5071a7fb
MD5 583b88c46fea6107e9e19815304b1602
BLAKE2b-256 9a6f059ca9719cf615e1bc75d982e3fbe452a87b51651dd8c8dfa9918d6099c8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page