castep输入的通用读写器
castepinput的Python项目详细描述
一个简单的castep输入文件解析器/编写器
这个包为castep的读写输入文件提供了一个基本的框架。
在ase中已经实现了一个优秀的读写器
但它们被赋予与ase
中的Atoms
和Calculator
类一起工作的角色。
它还需要一个CASTEP二进制来工作。
此包旨在为
编写和读取castep输入文件的简单(但重要)任务。
用法
用于读/写输入的两个类是ParamInput
和CellInput
。
关键字-值对的设置可以与字典相同。
例如:
fromcastepinputimportCellInput,ParamInput# ParamInput is in fact just a subclass of OrderedDictparam=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_abscell=CellInput(positions_abs=Block(["C 0 0 0","C 1 0 0"])
这两个类在写出内容时使用简单的字符串格式。 以下面的代码为例。
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 linecell['symmetry_generate']=''# Should give a string with a line 'symmetry_generate'cell.get_string()# Set cell and positions use the set methodscell.set_cell([10,10,10])cell.set_positions(["O","O"],[[0,0,0],[1.4,0,0]])# Save to filecell.save("O2.cell")
从现有的PARAM/CELL文件初始化,使用^ {< CD6>}方法。
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 settingcell["symmetry_generate"]
我们还尽量聪明,尽可能将字符串转换为python类型。
支持的类型有integer、float和由integer/float组成的一维数组。
加载文件时使用ParamInput.from_file(filename, plain=True)
可以避免这些覆盖。