Package: castepxbin
castepxbinDocumentationOverviewA collection of readers for binary output fromCASTEP.Available readers for:castep_bin: The compact checkpoint file contains all internal data stored by CASTEP (excluding the wavefunction) and may be read for restarting. High precision forces can be read from this file for single point calculations, as thegeomfile not written.check: Same ascastep_binbut includes wave function data (SCF kpoints).orbitals: Same ascheckbut includes wave function data for sampled (none-SCF) k-points in spectral/bandstructure/optics tasks.pdos_bin: Weights for computing the projected density of states.ome_bin: Optical matrix elements from theSpectraltask.dome_bin: Diagonal elements (band gradients) of the optical matrix from theSpectraltask.cst_ome: Legacy format containing optical matrix elements from theOpticstask.To-dos:cst_esp: Electrostatic potentials?elf: Electron localsation function.More data fromcastep_bin/checkfiles.InstallationThis package can be install usingpippip install castepxbinTo install extra dependencies may be needed for testing:pip install castepxbin[testing]Or directly from the GitHub repo:pip install git+https://github.com/zhubonan/castepxbin.gitThe two main dependencies arenumpyandscipy.
The optionalpymatgendependency is used for naming the orbitals.
Please note that the consistency of these labels for the f orbitals has not been checked.UsageSimply import the function and pass the file path. For thecastep_binreader, the example is shown below:In[1]:fromcastepxbinimportread_castep_binIn[2]:data=read_castep_bin("test_data/SiO2.castep_bin")In[3]:data.keys()Out[3]:dict_keys(['elec_temp','electronic_minimizer','nelectrons','nup','ndown','spin','charge','spin_treatment','num_ions_orig','max_ions_in_species_orig','real_lattice_orig','recip_lattice_orig','num_species_orig','num_ions_in_species_orig','ionic_positions','species_symbol_orig','num_ions','max_ions_in_species','real_lattice','recip_lattice','num_species','num_ions_in_species','species_symbol','nkpts','kpoints','kpoint_weights','found_ground_state_wavefunction','found_ground_state_density','total_energy','fermi_energy','nbands','nspins','occupancies','eigenvalues','kpoints_of_eigenvalues','ngx_fine','ngy_fine','ngz_fine','spin_density','charge_density','fermi_energy_second_spin','forces'])Note that these readers should be considered as "low-level" as they corresponds to unprocessed Fortran data as it is. Further processes are often needed, such reordering the axes (Fortran arrays are column-major) and recasting into differentdtypes.Once exception is for the optical matrix element reader, where output array are converted into the "C" (row-major) ordering internally.Extending thecastep_binreaderAt the moment, not all sections of thecastep_binis read (as there are too many!), but more contents can be added easily by including relevant sections in thecastepxbin.castep_bin.CASTEP_BIN_FIELD_SPECdictionary. Theread_castep_binfunction can accept such modified version instead of using the default one.For example, suppose the binary field is written as such:header='MY_SECTION'write(unit)headerwrite(unit)my_int#AnINTEGER(4)write(unit)my_bool#AnLOGICALtypewrite(unit)my_array#Anarrayofrealnumberswithsize(3,nspecies,my_int)header='END_MY_SECTION'write(unit)headerThe the following specifications can be added to read the section:my_spec=dict(CASTEP_BIN_FIELD_SPEC)my_spec['MY_SECTION']=(ScalarField('my_int',int),BoolField('my_bool'),ArrayField('my_array',float,shape=(3,'nspecies','my_int')))The value ofmy_intis unknown, but it is read before processing themy_arrayfield.
This imples that the order of fields inCASTEP_BIN_FIELD_SPECcan be important, as certain array sizes are only available from other fields, such as thenspeciesfield above.
However, even ifnspeciesis not read previously, it can still be resolved by inspecting the length of the record.
This would not be possible if there are two unknown dimension sizes.AcknowledgementThe data structures of binarypdos_bin,dome_bin,ome_bin, files are inferred from the code snippet
in the documentation of the open sourcedOptaDOSpackage for computing high quality DOS and other spectral properties using outputs from CASTEP.ContributorsBonan Zhu, University College LondonMatthew Evans, UCLouvain/University of Cambridge