Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ajjackson committed Apr 30, 2019
2 parents 379e91e + f7c32a7 commit 772b941
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 50 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ The changelog format is inspired by [keep-a-changelog](https://github.com/olivie

## [Unreleased]

## [1.1] - 2018-04-30

### Fixed
- Python3 compatibility
- Bug in decimal place tolerance option

### Added
- Comma-separated kgrid-series output option
- CASTEP-like reciprocal spacing cutoff (2 pi factor smaller than KSPACING)

### Changed
- Make filename a positional argument; -f or --filename no longer needed

## [1.0] - 2016-10-07

### Changed
Expand Down Expand Up @@ -46,6 +59,7 @@ The changelog format is inspired by [keep-a-changelog](https://github.com/olivie
- Optparse-based interface
- GPL

[Unreleased]: https://github.com/wmd-group/kgrid/compare/v1.0...HEAD
[Unreleased]: https://github.com/wmd-group/kgrid/compare/v1.1...HEAD
[1.1]: https://github.com/wmd-group/kgrid/compare/v1.0...v1.1
[1.0]: https://github.com/wmd-group/kgrid/compare/v0.2...v1.0
[0.2]: https://github.com/wmd-group/kgrid/compare/v0.1...v0.2
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kgrid
=====

Version 1.0: [Change log](./CHANGELOG.md)
Version 1.1: [Change log](./CHANGELOG.md)

Generates a suitably converged **k**-point grid for solid-state
quantum chemical calculations.
Expand Down Expand Up @@ -37,7 +37,7 @@ Two programs are provided: kgrid and kgrid-series
Requirements
------------

* Developed with Python 2.7; not tested with other versions
* Developed with Python 2.7 and Python 3.6
* [Atomic Simulation Environment](https://wiki.fysik.dtu.dk/ase) (ASE)
* [Numpy](www.numpy.org) (Also a requirement for ASE.)

Expand All @@ -48,7 +48,7 @@ Usage
From the command line

``` bash
kgrid -f FILE -t TYPE -c CUTOFF
kgrid FILE -t TYPE -c CUTOFF
```

will return a suggested set of mesh dimensions. FILE can be any
Expand Down Expand Up @@ -86,7 +86,7 @@ functional, using **kgrid** to determine the reciprocal-space sampling.
### kgrid-series

``` bash
kgrid-series -file FILE -t TYPE --min MIN --max MAX
kgrid-series FILE -t TYPE --min MIN --max MAX
```

Example output:
Expand Down Expand Up @@ -121,7 +121,11 @@ Length cutoff KSPACING Samples

```

Installation
Use the `--castep` option to replace KSPACING with "MP SPACING", which
corresponds to the *KPOINTS_MP_SPACING* parameter in CASTEP
(i.e. divide by 2π).

INSTALLATION
------------

**kgrid** uses setuptools; from a reasonable healthy Python environment you can use
Expand All @@ -133,7 +137,7 @@ with the usual pip caveats:
- the `--user` flag is highly recommended and avoids the need for administrator privileges, but on a somewhat unhealthy Python installation the user packages location may not be on your paths yet.
- the `-e` flag creates an "editable" installation which links to this repository and enables easy updates with git.

**kgrid** is not tested on Windows but no problems are anticipated; the Anaconda Python distribution includes pip.
**kgrid** is not developed on Windows but no problems are anticipated; the Anaconda Python distribution includes pip. We have had good experiences using the Windows subsystem for Linux (WSL), available on Windows 10.
On Mac OSX, the system Python does not include pip but there are various ways of getting a more complete distribution such as Homebrew or Anaconda.

Disclaimer
Expand Down
3 changes: 3 additions & 0 deletions kgrid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def calc_kpt_tuple(atoms, cutoff_length=10, realspace=False, mode='default'):
elif mode.lower() == 'kspacing':
cutoff_length = np.pi / cutoff_length
rounding = 'up'
elif mode.lower() == 'castep_mp_spacing':
cutoff_length = 1 / (2 * cutoff_length)
rounding = 'up'

if realspace:
return calc_kpt_tuple_naive(atoms, cutoff_length=cutoff_length,
Expand Down
35 changes: 17 additions & 18 deletions kgrid/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,12 @@ def calc_grid(cutoff_length,
def main():
parser = ArgumentParser()
parser.add_argument(
"structure",
type=str,
help="Path to input file",
nargs='?',
default=None
)
parser.add_argument(
"-f",
"--file",
action="store",
nargs="?",
type=str,
dest="file",
default="geometry.in",
help="Path to input file [default: ./geometry.in]")
help="Path to input file [default: ./geometry.in]")
threshold = parser.add_mutually_exclusive_group()
threshold.add_argument(
"-c",
Expand All @@ -82,7 +74,16 @@ def main():
action="store",
type=float,
dest="kspacing",
help="Reciprocal space distance like KSPACING in VASP")
help="Reciprocal-space distance like KSPACING in VASP")
threshold.add_argument(
"--castep",
"--castep_spacing",
"--castep_mp_spacing",
action="store",
type=float,
dest="castep_mp_spacing",
help=("Reciprocal-space distance like KPOINTS_MP_SPACING in CASTEP; "
"this differs from Vasp-like KSPACING by factor of 1/(2 pi)."))
parser.add_argument(
"-t",
"--type",
Expand All @@ -96,7 +97,7 @@ def main():
action="store_true",
help="Use real-space vector lengths instead of "
"computing reciprocal cell; not recommended!")
# Add further options here

args = parser.parse_args()

if args.vasp_auto:
Expand All @@ -105,19 +106,17 @@ def main():
elif args.kspacing:
mode = 'kspacing'
cutoff = args.kspacing
elif args.castep_mp_spacing:
mode = 'castep_mp_spacing'
cutoff = args.castep_mp_spacing
else:
mode = 'default'
cutoff = args.cutoff_length

if args.structure is None:
filename = args.file
else:
filename = args.structure

calc_grid(
cutoff,
mode=mode,
filename=filename,
filename=args.file,
filetype=args.type,
realspace=args.realspace,
pretty_print=True)
Expand Down
57 changes: 32 additions & 25 deletions kgrid/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
###############################################################################
from __future__ import print_function
from argparse import ArgumentParser

import numpy as np
from argparse import ArgumentParser

import ase.io
from kgrid import calc_kpt_tuple

from kgrid import calc_kpt_tuple

def get_increments(lattice_lengths):
"""
Expand Down Expand Up @@ -93,18 +94,9 @@ def kspacing_series(atoms, l_min, l_max, decimals=4):
def main():
parser = ArgumentParser("Calculate a systematic series of k-point samples")
parser.add_argument(
"structure",
type=str,
help="Path to input file",
'filename',
nargs='?',
default=None
)
parser.add_argument(
"-f",
"--file",
action="store",
type=str,
dest="file",
default="geometry.in",
help="Path to input file [default: ./geometry.in]")
parser.add_argument(
Expand All @@ -123,32 +115,47 @@ def main():
type=float,
default=30,
help='Maximum real-space cutoff / angstroms')
parser.add_argument('--comma_sep', action='store_true',
help='Output as comma-separated list on one line')
parser.add_argument('--castep', action='store_true',
help=('Provide CASTEP-like MP spacing instead of '
'vasp-like KSPACING'))

args = parser.parse_args()

if args.structure is None:
filename = args.file
else:
filename = args.structure

if args.type:
atoms = ase.io.read(filename, format=args.type)
atoms = ase.io.read(args.filename, format=args.type)
else:
atoms = ase.io.read(filename)
atoms = ase.io.read(args.filename)

cutoffs = cutoff_series(atoms, args.min, args.max)

kspacing = [np.pi / c for c in cutoffs]
if args.castep:
kspacing = [0.5 / c for c in cutoffs]
else:
kspacing = [np.pi / c for c in cutoffs]

samples = [calc_kpt_tuple(
atoms, cutoff_length=(cutoff - 1e-4)) for cutoff in cutoffs]

print("Length cutoff KSPACING Samples")
print("------------- -------- ------------")
if args.comma_sep:
def print_sample(sample):
return ' '.join((str(x) for x in sample))

print(','.join((print_sample(sample) for sample in samples)))

fstring = "{0:12.3f} {1:7.4f} {2:3d} {3:3d} {4:3d}"
for cutoff, s, sample in zip(cutoffs, kspacing, samples):
print(fstring.format(cutoff, s, *sample))
else:
if args.castep:
print("Length cutoff MP SPACING Samples")
print("------------- ---------- ------------")
fstring = "{0:12.3f} {1:9.6f} {2:3d} {3:3d} {4:3d}"
else:
print("Length cutoff KSPACING Samples")
print("------------- -------- ------------")
fstring = "{0:12.3f} {1:7.4f} {2:3d} {3:3d} {4:3d}"

for cutoff, s, sample in zip(cutoffs, kspacing, samples):
print(fstring.format(cutoff, s, *sample))


if __name__ == '__main__':
Expand Down

0 comments on commit 772b941

Please sign in to comment.