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
# 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
Built Distribution
File details
Details for the file castepinput-0.1.2.tar.gz
.
File metadata
- Download URL: castepinput-0.1.2.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c33338f7c4b274033a02fa4c553382d1317afbc0689ec32917677367b0c31d6 |
|
MD5 | 63bf467c5e03d0019487d4e5e8dd5e6a |
|
BLAKE2b-256 | bc47ecce48cd3a3fd4b1e5ff70581573b67d687499062887402ba44f266c1451 |
File details
Details for the file castepinput-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: castepinput-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa52ca9c9a82b8370918af10d27d394529dda57a88e5225c4786c3bcb3427a28 |
|
MD5 | c571625f468f6b71c76f5ffce7f4c74b |
|
BLAKE2b-256 | 4e297870f779129c04b6e477f5a96ae52bc5d16e240169c0cf88b2094f8450d7 |