1
0
mirror of https://github.com/TREX-CoE/fparser.git synced 2024-11-03 12:43:58 +01:00
fparser/README.md

246 lines
6.8 KiB
Markdown
Raw Normal View History

2021-03-25 18:09:43 +01:00
# A Modern Fortran-based Parser
2021-04-01 13:12:59 +02:00
| **Status** | ![Github issues](https://img.shields.io/github/issues/TREX-CoE/fparser) ![Pull Requests](https://img.shields.io/github/issues-pr/TREX-CoE/fparser) ![Github forks](https://img.shields.io/github/forks/TREX-CoE/fparser) ![Github stars](https://img.shields.io/github/stars/TREX-CoE/fparser) ![languages](https://img.shields.io/github/languages/count/TREX-CoE/fparser) ![Contributors](https://img.shields.io/github/contributors/TREX-CoE/fparser) |
2021-04-01 11:37:14 +02:00
| :------ | :------- |
| **License** | ![Github license](https://img.shields.io/github/license/TREX-CoE/fparser)|
2021-04-01 13:12:59 +02:00
<!--
- release ![Last release tag](https://img.shields.io/github/release/TREX-CoE/fparser)
- Commit Status ![commit-status](https://img.shields.io/github/commit-status/TREX-CoE/fparser)
- Last Modified ![Last Modified](https://img.shields.io/github/last-modified/TREX-CoE/fparser)
- languages ![languages](https://img.shields.io/github/languages/count/TREX-CoE/fparser)
- Contributors ![Contributors](https://img.shields.io/github/contributors/TREX-CoE/fparser)
- Commit Activity ![Commit Activity](https://img.shields.io/github/commit-activity/m/TREX-CoE/fparser)
- code coverage percentage: ![coverage](https://img.shields.io/badge/coverage-80%25-yellowgreen)
- stable release version: ![version](https://img.shields.io/badge/version-1.0.0-blue)
- package manager release: ![gem](https://img.shields.io/badge/gem-2.2.0-blue)
- status of third-party dependencies: ![dependencies](https://img.shields.io/badge/dependencies-out%20of%20date-orange)
- static code analysis grade: ![codacy](https://img.shields.io/badge/codacy-B-green)
- Python package downloads: ![downloads](https://img.shields.io/badge/downloads-13k%2Fmonth-brightgreen)
-->
2021-03-26 06:13:07 +01:00
This repository contains a modern Fortran-based input file parser. It uses a modified libfdf library.
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
---
2021-03-25 18:09:43 +01:00
## Get the code
2021-03-26 06:13:07 +01:00
The library is included in this repository as a submodule. To clone the entire project, do
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`git clone --recurse-submodules https://github.com/TREX-CoE/fparser.git`
2021-03-25 18:09:43 +01:00
## Compilation
2021-03-25 22:55:01 +01:00
The project contains two folders (a) modified-libfdf and (b) parser.
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
Compile and install the modified-libfdf using the following set of commands
`./configure --prefix=/usr/local FC=ifort CC=icc`
`make`
`sudo make install`
In the parser folder, link the modified libfdf library with the interface Fortran file.
2021-03-26 07:06:36 +01:00
`ifort -c m_periodic_table.F90 m_keywords.F90`
`ifort interface.F90 m_keywords.F90 m_periodic_table.F90 /usr/local/lib/libfdf.a`
2021-03-26 06:13:07 +01:00
2021-03-25 18:09:43 +01:00
## Integrate parser in your code
2021-03-26 06:13:07 +01:00
Just include the interface.F90 file and the keyword declaration module files in the existing Makefile of your code.
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
---
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
## Features of the parser (including inheritance from libfdf)
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
- Blank lines and lines starting with # are ignored.
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
- The order of keyword-value pairs does not matter
2021-03-25 18:09:43 +01:00
2021-03-30 16:17:04 +02:00
- Spaces and tabs are ignored; keyword-value pairs are parsed in a free-form.
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
- Keywords are case insensitive.
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
- A default value can be set for keywords not present in the input file.
2021-03-25 18:09:43 +01:00
2021-03-30 16:17:04 +02:00
- Large data can be parsed using the %block structure.
- Multiple keyword-value pairs can be clubbed together in a %module structure.
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
## Syntax
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
1. Include another input file for parser to read using:
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
` %include global.inp`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
2. Include a data file for parser to read using:
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
` load label filename`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
3. Here, depending upon the label, parser will provide the filename. For example,
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
` load basis cc-pvtz.gbs`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
4. Read molecular coordinates directly from the input file using
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
```perl
%block molecule
12
#benzene comment
C 0.00000 1.40272 0
H 0.00000 2.49029 0
C -1.21479 0.70136 0
H -2.15666 1.24515 0
C -1.21479 -0.70136 0
H -2.15666 -1.24515 0
C 0.00000 -1.40272 0
H 0.00000 -2.49029 0
C 1.21479 -0.70136 0
H 2.15666 -1.24515 0
C 1.21479 0.70136 0
H 2.15666 1.24515 0
%endblock
```
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
5. Read molecular coordinates from an external .xyz file using
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
` %block molecule < benzene.xyz `
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
6. Group certain keywords using the %module construct
2021-03-25 18:09:43 +01:00
2021-03-30 16:17:04 +02:00
```Fortran
2021-03-26 06:13:07 +01:00
%module DMC
tau = 0.04
etrial = -15 Ha
%endmodule
```
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
7. Logical variables accept `true`, `TRUE`, `T`, `.true.` as valid keywords for `True`. The `fdf_boolean` function can also take "1" as true and "0" as false from the input.
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
` optimize_wavefunction true`
2021-03-25 18:09:43 +01:00
2021-03-26 09:15:13 +01:00
8. Single and Double precision numbers along with numbers in scientific format can be read using the `fdf_get()` function.
The second number in the bracket denotes the default value.
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`energy_tol = fdf_get('energy_tol', 0.00001d0)`
2021-03-25 18:09:43 +01:00
2021-03-26 06:17:26 +01:00
9. Floats/integers/strings/booleans can be parsed generically using the interface `fdf_get()` function. Strings are limited to 132 characters per line.
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
` sr_tau = fdf_get('sr_tau', 0.025d0)`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
` nspin1 = fdf_get('nspin1', 1)`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
` opt_method = fdf_get('opt_method', "sr_n")`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
` multiple_adiag = fdf_get('multiple_adiag', .false.)`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
10. Units can be specified to variables. Unit conversion is possible at the parsing.
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
If the input file has `etrial = -15 Ha` entry, the `etrial` variable can be assigned values using the `fdf_physical` function with unit conversion.
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
` etrial = fdf_physical('etrial', -20.d0, 'eV')`
11. List of public functions available for parsing the data:
Initiate
`fdf_init`
`fdf_shutdown`
Single data
`fdf_get`
`fdf_integer`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_single`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_double`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_string`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_boolean`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_physical`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_convfac`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_load_filename`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
Lists (data enclosed in [])
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_islist`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_islinteger`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_islreal`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_list`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_linteger`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_ldouble`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
Returns the string associated with a mark line
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_getline`
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
Test if a label is defined
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
`fdf_defined`
`fdf_isphysical`
`fdf_isblock`
`fdf_load_defined`
Allow to overwrite things in the FDF
`fdf_overwrite`
`fdf_removelabel`
`fdf_addline`
Block reading (processing each line of data)
`fdf_block, fdf_block_linecount`
`fdf_bline, fdf_bbackspace, fdf_brewind, fdf_bclose`
`fdf_bnintegers, fdf_bnreals, fdf_bnvalues, fdf_bnnames, fdf_bntokens`
`fdf_bintegers, fdf_breals, fdf_bvalues, fdf_bnames, fdf_btokens`
`fdf_bboolean, fdf_bphysical`
`fdf_bnlists, fdf_bnilists, fdf_bnrlists, fdf_bnvlists`
`fdf_bilists, fdf_brlists, fdf_bvlists`
Match, search over blocks, and destroy block structure
`fdf_bmatch, fdf_bsearch, fdf_substring_search`
`fdf_setoutput, fdf_setdebug`
---
2021-03-25 18:09:43 +01:00
2021-03-26 06:13:07 +01:00
## Demonstration
2021-03-25 18:09:43 +01:00
2021-03-26 06:40:19 +01:00
In the `parser` folder, we have included a sample `interface.F90` and `m_keywords.F90` files.
In the `interface.F90` file, we have demonstrated how keyword-values pairs, simple data blocks,
and data from external files can be read easily.
2021-03-25 18:09:43 +01:00