ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
ModuleIO::CifParser Class Reference

#include <cif_io.h>

Collaboration diagram for ModuleIO::CifParser:

Public Member Functions

 CifParser ()=delete
 
 CifParser (const std::string &fcif)
 
 ~CifParser ()
 
std::vector< std::string > get (const std::string &key)
 get information by key from the stored information of cif file, if the key is not found, an empty vector will be returned.
 

Static Public Member Functions

static void write (const std::string &fcif, const double *abc_angles, const int natom, const std::string *atom_site_labels, const double *atom_site_fract_coords, const std::string &title="# generated by ABACUS", const std::string &data_tag="data_?", const int rank=0, const double *atom_site_occups=nullptr, const std::string &cell_formula_units_z="1")
 Print the CIF file from the given information.
 
static void write (const std::string &fcif, const std::vector< double > &abc_angles, const std::vector< std::string > &atom_site_labels, const std::vector< double > &atom_site_fract_coords, const std::string &title="# generated by ABACUS", const std::string &data_tag="data_?", const int rank=0, const std::vector< double > &atom_site_occups={}, const std::string &cell_formula_units_z="1")
 A Pybind wrapper for the static method write.
 
static void write (const std::string &fcif, const UnitCell &ucell, const std::string &title="# generated by ABACUS", const std::string &data_tag="data_?", const int rank=0)
 Write CIF file with the whole UnitCell instance.
 
static void read (const std::string &fcif, std::map< std::string, std::vector< std::string > > &out, const int rank=0)
 Read the CIF file and store the information in the map.
 

Static Private Member Functions

static void _unpack_ucell (const UnitCell &ucell, std::vector< double > &veca, std::vector< double > &vecb, std::vector< double > &vecc, int &natom, std::vector< std::string > &atom_site_labels, std::vector< double > &atom_site_fract_coords)
 

Private Attributes

std::map< std::string, std::vector< std::string > > raw_
 

Detailed Description

CifParser

INTRODUCTION

In short

Tools for CIF file I/O.

Supported structure of CIF

A example (official template of CIF) is shown here (https://www.iucr.org/__data/iucr/ftp/pub/form.cif), but present impl. is ONLY capable to parse a CIF with ONE structure. If there are multiple structures in the CIF file, unexpected behavior may occur.

A CIF file always contain two kinds of data structure, the first is simply the key-value pair, the second is table which is lead by a keyword "loop_".

Key-value pair

key-value pair can have two types:

Type 1: the most general _KEY1 VALUE1 _KEY2 VALUE2 ... Type 2: text box _KEY1 ; very long text VeRy LoNg TeXt ... ;

Table

The table in CIF must be lead by a keyword "loop_", and all titles of the columns will be list first, then all the rest are the values of the table. For example: loop_ _KEY1 _KEY2 _KEY3 ... VALUE11 VALUE21 VALUE31 VALUE12 VALUE22 VALUE32 ... Once the number of values cannot be divided by the number of keys, will cause an assertion error.

Usage of this "class"

Read CIF file and store the information in a map

type the following line: std::map<std::string, std::vector<std::string>> cif_info; ModuleIO::CifParser::read("test.cif", cif_info);

Information of the cif file will stored in key-value pair manner, like cif_info["_cell_length_a"] = {"2.46772428"}; cif_info["_cell_length_b"] = {"2.46772428"}; ... cif_info["_atom_site_label"] = {"C1", "C2", ...}; cif_info["_atom_site_fract_x"] = {"0.00000000", "0.33333300", ...}; ... NOTE1: only keys in table will have value with length larger than 1, otherwise all words will be saved in the only element in std::vector<std::string>. For example please see unittest of this class at source/source_io/test/cif_io_test.cpp. NOTE2: One should note that for some cif files, the number will be in the format like "0.00000000(1)", which means the uncertainty of the number is 1 in the last digit. In this case, user should be careful to convert the string to double by its own.

Write CIF file with the given information.

ModuleIO::CifParser::write("test.cif", ...); For detailed usage, see the static methods in the class. A to-be-deprecated usage is simple as: ModuleIO::CifParser cif("test.cif", ucell); , where ucell is an instance of UnitCell. This usage is not encouraged.

Pythonization information

  1. function write it is recommended to pythonize the 2nd overload of this function, the 3rd one will be deprecated in the future.
  2. function read this function can be directly pythonized.

Constructor & Destructor Documentation

◆ CifParser() [1/2]

ModuleIO::CifParser::CifParser ( )
delete

◆ CifParser() [2/2]

ModuleIO::CifParser::CifParser ( const std::string &  fcif)

◆ ~CifParser()

ModuleIO::CifParser::~CifParser ( )
inline

Member Function Documentation

◆ _unpack_ucell()

void ModuleIO::CifParser::_unpack_ucell ( const UnitCell ucell,
std::vector< double > &  veca,
std::vector< double > &  vecb,
std::vector< double > &  vecc,
int &  natom,
std::vector< std::string > &  atom_site_labels,
std::vector< double > &  atom_site_fract_coords 
)
staticprivate

◆ get()

std::vector< std::string > ModuleIO::CifParser::get ( const std::string &  key)

get information by key from the stored information of cif file, if the key is not found, an empty vector will be returned.

Parameters
keythe key to search
Returns
std::vector<std::string>. Only columns in table will have more than one element, otherwise all the information will be stored in the only element (the first).

◆ read()

void ModuleIO::CifParser::read ( const std::string &  fcif,
std::map< std::string, std::vector< std::string > > &  out,
const int  rank = 0 
)
static

Read the CIF file and store the information in the map.

Parameters
fcifthe input cif file name
outthe output map containing the information
rankthe rank which reads the CIF file
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write() [1/3]

void ModuleIO::CifParser::write ( const std::string &  fcif,
const double *  abc_angles,
const int  natom,
const std::string *  atom_site_labels,
const double *  atom_site_fract_coords,
const std::string &  title = "# generated by ABACUS",
const std::string &  data_tag = "data_?",
const int  rank = 0,
const double *  atom_site_occups = nullptr,
const std::string &  cell_formula_units_z = "1" 
)
static

Print the CIF file from the given information.

Parameters
fcifthe output cif file name
abc_anglescell A B C angles in the form of [a, b, c, alpha, beta, gamma]
natomthe number of atoms
atom_site_labelsthe atom site labels in the form of [atom1, atom2, ...]
atom_site_fract_coordsthe fractional coordinates of the atoms in the form of [x1, y1, z1, x2, y2, z2, ...]
titlethe title of the CIF file
data_tagthe data tag of the CIF file
rankthe rank which writes the CIF file
atom_site_occupsthe occupancies of the atoms in the form of [occup1, occup2, ...]
cell_formula_units_zthe cell formula units Z
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write() [2/3]

void ModuleIO::CifParser::write ( const std::string &  fcif,
const std::vector< double > &  abc_angles,
const std::vector< std::string > &  atom_site_labels,
const std::vector< double > &  atom_site_fract_coords,
const std::string &  title = "# generated by ABACUS",
const std::string &  data_tag = "data_?",
const int  rank = 0,
const std::vector< double > &  atom_site_occups = {},
const std::string &  cell_formula_units_z = "1" 
)
static

A Pybind wrapper for the static method write.

Parameters
fcifthe output cif file name
abc_anglescell A B C angles in the form of [a, b, c, alpha, beta, gamma]
atom_site_labelsthe atom site labels in the form of [atom1, atom2, ...]
atom_site_fract_coordsthe fractional coordinates of the atoms in the form of [x1, y1, z1, x2, y2, z2, ...]
titlethe title of the CIF file
data_tagthe data tag of the CIF file
rankthe rank which writes the CIF file
atom_site_occupsthe occupancies of the atoms in the form of [occup1, occup2, ...]
cell_formula_units_zthe cell formula units Z

◆ write() [3/3]

void ModuleIO::CifParser::write ( const std::string &  fcif,
const UnitCell ucell,
const std::string &  title = "# generated by ABACUS",
const std::string &  data_tag = "data_?",
const int  rank = 0 
)
static

Write CIF file with the whole UnitCell instance.

Parameters
fcifthe output cif file name
ucellthe input UnitCell instance
titlethe title of the CIF file
data_tagthe data tag of the CIF file
rankthe rank which writes the CIF file
Here is the call graph for this function:

Member Data Documentation

◆ raw_

std::map<std::string, std::vector<std::string> > ModuleIO::CifParser::raw_
private

The documentation for this class was generated from the following files: