├── .github
└── workflows
│ ├── pylint.yml
│ └── pytest.yml
├── .gitignore
├── CHANGELOG.md
├── README.md
├── license.md
├── mctools
├── __init__.py
├── generic
│ ├── __init__.py
│ ├── fold_prim.py
│ ├── get_energy.py
│ ├── get_minimum.py
│ ├── get_primitive.py
│ ├── get_spacegroup.py
│ ├── get_volume.py
│ └── vectors.py
├── mace
│ ├── __init__.py
│ └── tail_mace_fit.py
├── other
│ ├── __init__.py
│ ├── plot_cplap_ternary.py
│ ├── sendto.py
│ └── sqs_read.py
├── phonon
│ ├── __init__.py
│ └── phonon_dispersion_compare.py
└── vasp
│ ├── __init__.py
│ ├── get_vbm.py
│ └── vasp_charge.py
├── pyproject.toml
└── tests
├── test_get_energy.py
├── test_get_primitive.py
└── test_get_spacegroup.py
/.github/workflows/pylint.yml:
--------------------------------------------------------------------------------
1 | name: Pylint
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 | strategy:
9 | matrix:
10 | python-version: ["3.11"]
11 | steps:
12 | - uses: actions/checkout@v3
13 | - name: Set up Python ${{ matrix.python-version }}
14 | uses: actions/setup-python@v3
15 | with:
16 | python-version: ${{ matrix.python-version }}
17 | - name: Install dependencies
18 | run: |
19 | python -m pip install --upgrade pip
20 | pip install pylint
21 | pip install .
22 | - name: Analysing the code with pylint
23 | run: |
24 | pylint $(git ls-files 'mctools/*.py') --fail-under 8.1
25 |
--------------------------------------------------------------------------------
/.github/workflows/pytest.yml:
--------------------------------------------------------------------------------
1 | name: Pytest
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 | strategy:
9 | matrix:
10 | python-version: ["3.9", "3.11"]
11 | steps:
12 | - uses: actions/checkout@v3
13 | - name: Set up Python ${{ matrix.python-version }}
14 | uses: actions/setup-python@v3
15 | with:
16 | python-version: ${{ matrix.python-version }}
17 | - name: Install dependencies
18 | run: |
19 | python -m pip install --upgrade pip
20 | python -m pip install pytest flake8 flake8-pytest-style
21 | pip install .
22 | - name: Lint the test files with flake8-pytest-style
23 | run: |
24 | flake8 tests/
25 | - name: Test with pytest
26 | run: |
27 | pytest
28 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pyc
2 | mctools.egg-info
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | Notable changes are logged here by release. This project is not
4 | expected to be especially active and follows a simplified Semantic Versioning:
5 |
6 | - Version numbers take the format X.Y
7 | - X is associated with major API breakage / changes in algorithm and results.
8 | - Y is associated with minor updates and improvements
9 | - Small amounts of code tidying, refactoring and documentation do not
10 | lead to a new release, and simply sit on the Development branch of
11 | the Git repository.
12 |
13 | The changelog format is inspired by [keep-a-changelog](https://github.com/olivierlacan/keep-a-changelog).
14 |
15 | ## [Unreleased]
16 |
17 | ### Packaging and testing
18 | - mctools now uses a pyproject.toml file
19 | - the mctools package has been reorganised into submodules, grouping tools that have a similar scope
20 | - mctools now includes a few tests; automatic testing and linting are run with github actions
21 |
22 | ### Compatibility
23 | - `get_spacegroup` and `get_primitive` are made compatible with modern versions of spglib
24 |
25 | ### Major changes
26 | - get_primitive output format has changed and is now a lot more legible
27 | - output format can be controlled with `--precision` argument
28 |
29 | - `ase-convert` has been removed: use `ase convert` instead
30 |
31 | ### New tools
32 | - multi-phonon-dispersion plotter based on Euphonic
33 | - live MACE fitting plotter
34 |
35 | ## [1.1] - 2024-04-19
36 | Slap a version number on "unreleased" stuff before API-breaking v2
37 |
38 | - "sendto" now looks for a config file in home directory
39 | - "sendto" options to skip large VASP files
40 | - New CPLAP plotter
41 | - Add "get-minimum" for quick extraction of low-energy structure from trajectory
42 |
43 | ## [1.0] - 2017-04-25
44 |
45 | - Add "get-volume" for quick read of volume
46 | - Add "get-energy" for quick read of energy
47 | - Update all "get" tools for Python3 compatibility and simpler interface
48 | - Input file is now consistently the first positional argument so no
49 | need to remember which optional flag is needed.
50 |
51 | ## [0.2] - 2016-03-01
52 |
53 | - Fix broken get-spacegroup interface
54 | - Add reader/converter for ATAT SQS files
55 |
56 | ## 0.1 - 2016-11-04
57 |
58 | - Begin proper organisation of repository and packaging
59 | - Tools collected from various projects
60 | - Reasonably functional components
61 | - ase-convert
62 | - get-primitive
63 | - get-spacegroup
64 | - vectors
65 | - Primitive / work-in-progress
66 | - get-vbm
67 | - vasp-charge
68 | - Possibly too "personal"
69 | - sendto
70 | - Packaging with pip
71 | - GPL license
72 |
73 | [Unreleased]: https://github.com/ajjackson/mctools/compare/v1.1...HEAD
74 | [1.1]: https://github.com/ajjackson/mctools/compare/v1.0...v1.1
75 | [1.0]: https://github.com/ajjackson/mctools/compare/v0.2...v1.0
76 | [0.2]: https://github.com/ajjackson/mctools/compare/v0.1...v0.2
77 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MCTOOLS
2 |
3 | Collection of generic pre- and post- processing tools using the [Atomic Simulation Environment](https://wiki.fysik.dtu.dk/ase).
4 | Developed while working with [Walsh Materials Design](https://github.com/wmd-group), kept on as a personal toolkit
5 | and developed further while at [Scanlon Materials Theory Group](https://github.com/smtg-ucl).
6 |
7 | The recommended way of installing is to clone the repository and make a local installation using pip:
8 |
9 | ```bash
10 | git clone https://github.com/ajjackson/mctools.git
11 | cd mctools
12 | pip install --user -e .
13 | ```
14 |
15 | To run unit tests, install pytest and run with
16 | ```bash
17 | python -m pytest
18 | ```
19 |
20 | get-spacegroup (Spacegroup tolerances)
21 | --------------------------------------
22 | Use [Spglib](http://spg.sourceforge.net) to analyse the symmetry of a
23 | crystal structure file over a range of distance thresholds. This can
24 | be useful for identifying when numerical noise or limited convergence
25 | has resulted in a lower-symmetry spacegroup, as well as for quickly
26 | checking the identity of an unknown structure. Call with `-h` flag for
27 | usage information.
28 |
29 | ```
30 | # EXAMPLE
31 | bash> get_spacegroup.py -i geometry.in.next_step
32 | | Threshold / Å | Space group |
33 | |---------------|-------------------|
34 | | 0.00001 | P-1 (2) |
35 | | 0.00010 | P-1 (2) |
36 | | 0.00050 | C2/m (12) |
37 | | 0.00100 | C2/m (12) |
38 | | 0.00500 | P-3m1 (164) |
39 | | 0.01000 | P-3m1 (164) |
40 | | 0.05000 | P-3m1 (164) |
41 | | 0.10000 | P-3m1 (164) |
42 | ```
43 |
44 | get-minimum (Extract optimum from trajectory)
45 | ---------------------------------------------
46 | Use ASE to import a trajectory, typically a vasprun.xml or OUTCAR file
47 | from a structure relaxation. Find the step with lowest energy and
48 | write it out to a file. This is useful for salvaging optimisation
49 | calculations that get 'lost'.
50 |
51 | get-primitive (Primitive cell generator)
52 | ----------------------------------------
53 | Use [Spglib](http://spg.sourceforge.net) to generate a primitive cell
54 | from/to any ASE-supported structure file format. It can be helpful to
55 | use **get_spacegroup.py** first in order to identify an appropriate
56 | symmetry threshold. Call with `-h` flag for usage information.
57 |
58 | plot-cplap-ternary (Pretty plotting for CPLAP outputs)
59 | ------------------------------------------------------
60 | This is an alternative plotter to the GNUplot scripts generated by the
61 | Chemical Potential Limits Analysis Program (CPLAP).
62 | ([website](https://sourceforge.net/projects/cplap/),
63 | [paper](https://doi.org/10.1016/j.cpc.2013.08.026))
64 | Specifically it deals with analysis of ternary systems where one phase is set
65 | as the dependent variable.
66 | All of the necessary data is read from the *grid.dat* and
67 | *2Dplot.txt* output files, including the elements and compound
68 | formulae. The chemical potential of the dependent element is
69 | displayed as a colour map on the stability region.
70 | The plotter makes use of various matplotlib features (choice of file
71 | formats, appearance customisation with style sheets) to generate
72 | publication/presentation-quality graphics.
73 |
74 | sendto (submission to remote server)
75 | ------------------------------------
76 |
77 | Copy the current directory to a specified remote server. The server
78 | accounts must be set up in sendto.conf. This is a convenience tool for
79 | copying files around, and does not submit to a queue.
80 |
81 | sqs-read (ATAT SQS file reader)
82 | -------------------------------
83 |
84 | Read a "bestsqs.out" file as generated by the
85 | [ATAT mcsqs](https://www.brown.edu/Departments/Engineering/Labs/avdw/atat/manual/node46.html)
86 | tool. Print to standard output, optionally write
87 | file or open ASE GUI.
88 |
89 | fold-prim (ATAT/BANDUP glue)
90 | ----------------------------
91 |
92 | Computing the unfolded band structure of a disordered or alloy
93 | material requires a reference primitive cell, but it makes no
94 | sense to compute such a cell. This tool will generate a "dummy"
95 | primitive cell from a relaxed supercell, given the supercell
96 | matrix.
97 |
98 |
99 | vasp-charge (Electron counting)
100 | -------------------------------
101 |
102 | WORK IN PROGRESS
103 |
104 | Report the number of electrons in a proposed vasp calculation
105 | (NELECT). The name refers to an intended feature (specify system
106 | charge). At the moment there is no real user interface.
107 |
108 | Uses the VASP_PP_PATH environment variable; if you use ASE for VASP
109 | calculations this should be set up. Otherwise it will not work.
110 |
111 | vectors (Lattice vectors)
112 | -------------------------
113 |
114 | Report lattice vectors in a, b, c, alpha, beta, gamma format. This is
115 | useful for comparing structures and makes for more compact and
116 | intuitive reporting. Call with `-h` flag for usage information.
117 |
118 | ```
119 | # EXAMPLE
120 | bash> vectors.py geometry.in
121 | a b c alpha beta gamma
122 | 11.451 3.856 6.193 90.00 103.21 90.00
123 | ```
124 |
125 | Related Repositories
126 | ------
127 | ###### [k-grid (Mesh densities)](https://github.com/WMD-Bath/kgrid)
128 | Optimal k-point meshes with a single convergence parameter
129 | ###### [RVO (Optimisation tool)](https://github.com/WMD-Bath/rvo)
130 | Rapid volume optimisation with an auxiliary equation of state
131 |
--------------------------------------------------------------------------------
/license.md:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | ==========================
3 |
4 | Version 3, 29 June 2007
5 |
6 | Copyright © 2007 Free Software Foundation, Inc. <>
7 |
8 | Everyone is permitted to copy and distribute verbatim copies of this license
9 | document, but changing it is not allowed.
10 |
11 | ## Preamble
12 |
13 | The GNU General Public License is a free, copyleft license for software and other
14 | kinds of works.
15 |
16 | The licenses for most software and other practical works are designed to take away
17 | your freedom to share and change the works. By contrast, the GNU General Public
18 | License is intended to guarantee your freedom to share and change all versions of a
19 | program--to make sure it remains free software for all its users. We, the Free
20 | Software Foundation, use the GNU General Public License for most of our software; it
21 | applies also to any other work released this way by its authors. You can apply it to
22 | your programs, too.
23 |
24 | When we speak of free software, we are referring to freedom, not price. Our General
25 | Public Licenses are designed to make sure that you have the freedom to distribute
26 | copies of free software (and charge for them if you wish), that you receive source
27 | code or can get it if you want it, that you can change the software or use pieces of
28 | it in new free programs, and that you know you can do these things.
29 |
30 | To protect your rights, we need to prevent others from denying you these rights or
31 | asking you to surrender the rights. Therefore, you have certain responsibilities if
32 | you distribute copies of the software, or if you modify it: responsibilities to
33 | respect the freedom of others.
34 |
35 | For example, if you distribute copies of such a program, whether gratis or for a fee,
36 | you must pass on to the recipients the same freedoms that you received. You must make
37 | sure that they, too, receive or can get the source code. And you must show them these
38 | terms so they know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps: (1) assert
41 | copyright on the software, and (2) offer you this License giving you legal permission
42 | to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains that there is
45 | no warranty for this free software. For both users' and authors' sake, the GPL
46 | requires that modified versions be marked as changed, so that their problems will not
47 | be attributed erroneously to authors of previous versions.
48 |
49 | Some devices are designed to deny users access to install or run modified versions of
50 | the software inside them, although the manufacturer can do so. This is fundamentally
51 | incompatible with the aim of protecting users' freedom to change the software. The
52 | systematic pattern of such abuse occurs in the area of products for individuals to
53 | use, which is precisely where it is most unacceptable. Therefore, we have designed
54 | this version of the GPL to prohibit the practice for those products. If such problems
55 | arise substantially in other domains, we stand ready to extend this provision to
56 | those domains in future versions of the GPL, as needed to protect the freedom of
57 | users.
58 |
59 | Finally, every program is threatened constantly by software patents. States should
60 | not allow patents to restrict development and use of software on general-purpose
61 | computers, but in those that do, we wish to avoid the special danger that patents
62 | applied to a free program could make it effectively proprietary. To prevent this, the
63 | GPL assures that patents cannot be used to render the program non-free.
64 |
65 | The precise terms and conditions for copying, distribution and modification follow.
66 |
67 | ## TERMS AND CONDITIONS
68 |
69 | ### 0. Definitions.
70 |
71 | “This License” refers to version 3 of the GNU General Public License.
72 |
73 | “Copyright” also means copyright-like laws that apply to other kinds of
74 | works, such as semiconductor masks.
75 |
76 | “The Program” refers to any copyrightable work licensed under this
77 | License. Each licensee is addressed as “you”. “Licensees” and
78 | “recipients” may be individuals or organizations.
79 |
80 | To “modify” a work means to copy from or adapt all or part of the work in
81 | a fashion requiring copyright permission, other than the making of an exact copy. The
82 | resulting work is called a “modified version” of the earlier work or a
83 | work “based on” the earlier work.
84 |
85 | A “covered work” means either the unmodified Program or a work based on
86 | the Program.
87 |
88 | To “propagate” a work means to do anything with it that, without
89 | permission, would make you directly or secondarily liable for infringement under
90 | applicable copyright law, except executing it on a computer or modifying a private
91 | copy. Propagation includes copying, distribution (with or without modification),
92 | making available to the public, and in some countries other activities as well.
93 |
94 | To “convey” a work means any kind of propagation that enables other
95 | parties to make or receive copies. Mere interaction with a user through a computer
96 | network, with no transfer of a copy, is not conveying.
97 |
98 | An interactive user interface displays “Appropriate Legal Notices” to the
99 | extent that it includes a convenient and prominently visible feature that (1)
100 | displays an appropriate copyright notice, and (2) tells the user that there is no
101 | warranty for the work (except to the extent that warranties are provided), that
102 | licensees may convey the work under this License, and how to view a copy of this
103 | License. If the interface presents a list of user commands or options, such as a
104 | menu, a prominent item in the list meets this criterion.
105 |
106 | ### 1. Source Code.
107 |
108 | The “source code” for a work means the preferred form of the work for
109 | making modifications to it. “Object code” means any non-source form of a
110 | work.
111 |
112 | A “Standard Interface” means an interface that either is an official
113 | standard defined by a recognized standards body, or, in the case of interfaces
114 | specified for a particular programming language, one that is widely used among
115 | developers working in that language.
116 |
117 | The “System Libraries” of an executable work include anything, other than
118 | the work as a whole, that (a) is included in the normal form of packaging a Major
119 | Component, but which is not part of that Major Component, and (b) serves only to
120 | enable use of the work with that Major Component, or to implement a Standard
121 | Interface for which an implementation is available to the public in source code form.
122 | A “Major Component”, in this context, means a major essential component
123 | (kernel, window system, and so on) of the specific operating system (if any) on which
124 | the executable work runs, or a compiler used to produce the work, or an object code
125 | interpreter used to run it.
126 |
127 | The “Corresponding Source” for a work in object code form means all the
128 | source code needed to generate, install, and (for an executable work) run the object
129 | code and to modify the work, including scripts to control those activities. However,
130 | it does not include the work's System Libraries, or general-purpose tools or
131 | generally available free programs which are used unmodified in performing those
132 | activities but which are not part of the work. For example, Corresponding Source
133 | includes interface definition files associated with source files for the work, and
134 | the source code for shared libraries and dynamically linked subprograms that the work
135 | is specifically designed to require, such as by intimate data communication or
136 | control flow between those subprograms and other parts of the work.
137 |
138 | The Corresponding Source need not include anything that users can regenerate
139 | automatically from other parts of the Corresponding Source.
140 |
141 | The Corresponding Source for a work in source code form is that same work.
142 |
143 | ### 2. Basic Permissions.
144 |
145 | All rights granted under this License are granted for the term of copyright on the
146 | Program, and are irrevocable provided the stated conditions are met. This License
147 | explicitly affirms your unlimited permission to run the unmodified Program. The
148 | output from running a covered work is covered by this License only if the output,
149 | given its content, constitutes a covered work. This License acknowledges your rights
150 | of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not convey, without
153 | conditions so long as your license otherwise remains in force. You may convey covered
154 | works to others for the sole purpose of having them make modifications exclusively
155 | for you, or provide you with facilities for running those works, provided that you
156 | comply with the terms of this License in conveying all material for which you do not
157 | control copyright. Those thus making or running the covered works for you must do so
158 | exclusively on your behalf, under your direction and control, on terms that prohibit
159 | them from making any copies of your copyrighted material outside their relationship
160 | with you.
161 |
162 | Conveying under any other circumstances is permitted solely under the conditions
163 | stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
164 |
165 | ### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
166 |
167 | No covered work shall be deemed part of an effective technological measure under any
168 | applicable law fulfilling obligations under article 11 of the WIPO copyright treaty
169 | adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention
170 | of such measures.
171 |
172 | When you convey a covered work, you waive any legal power to forbid circumvention of
173 | technological measures to the extent such circumvention is effected by exercising
174 | rights under this License with respect to the covered work, and you disclaim any
175 | intention to limit operation or modification of the work as a means of enforcing,
176 | against the work's users, your or third parties' legal rights to forbid circumvention
177 | of technological measures.
178 |
179 | ### 4. Conveying Verbatim Copies.
180 |
181 | You may convey verbatim copies of the Program's source code as you receive it, in any
182 | medium, provided that you conspicuously and appropriately publish on each copy an
183 | appropriate copyright notice; keep intact all notices stating that this License and
184 | any non-permissive terms added in accord with section 7 apply to the code; keep
185 | intact all notices of the absence of any warranty; and give all recipients a copy of
186 | this License along with the Program.
187 |
188 | You may charge any price or no price for each copy that you convey, and you may offer
189 | support or warranty protection for a fee.
190 |
191 | ### 5. Conveying Modified Source Versions.
192 |
193 | You may convey a work based on the Program, or the modifications to produce it from
194 | the Program, in the form of source code under the terms of section 4, provided that
195 | you also meet all of these conditions:
196 |
197 | * a) The work must carry prominent notices stating that you modified it, and giving a
198 | relevant date.
199 | * b) The work must carry prominent notices stating that it is released under this
200 | License and any conditions added under section 7. This requirement modifies the
201 | requirement in section 4 to “keep intact all notices”.
202 | * c) You must license the entire work, as a whole, under this License to anyone who
203 | comes into possession of a copy. This License will therefore apply, along with any
204 | applicable section 7 additional terms, to the whole of the work, and all its parts,
205 | regardless of how they are packaged. This License gives no permission to license the
206 | work in any other way, but it does not invalidate such permission if you have
207 | separately received it.
208 | * d) If the work has interactive user interfaces, each must display Appropriate Legal
209 | Notices; however, if the Program has interactive interfaces that do not display
210 | Appropriate Legal Notices, your work need not make them do so.
211 |
212 | A compilation of a covered work with other separate and independent works, which are
213 | not by their nature extensions of the covered work, and which are not combined with
214 | it such as to form a larger program, in or on a volume of a storage or distribution
215 | medium, is called an “aggregate” if the compilation and its resulting
216 | copyright are not used to limit the access or legal rights of the compilation's users
217 | beyond what the individual works permit. Inclusion of a covered work in an aggregate
218 | does not cause this License to apply to the other parts of the aggregate.
219 |
220 | ### 6. Conveying Non-Source Forms.
221 |
222 | You may convey a covered work in object code form under the terms of sections 4 and
223 | 5, provided that you also convey the machine-readable Corresponding Source under the
224 | terms of this License, in one of these ways:
225 |
226 | * a) Convey the object code in, or embodied in, a physical product (including a
227 | physical distribution medium), accompanied by the Corresponding Source fixed on a
228 | durable physical medium customarily used for software interchange.
229 | * b) Convey the object code in, or embodied in, a physical product (including a
230 | physical distribution medium), accompanied by a written offer, valid for at least
231 | three years and valid for as long as you offer spare parts or customer support for
232 | that product model, to give anyone who possesses the object code either (1) a copy of
233 | the Corresponding Source for all the software in the product that is covered by this
234 | License, on a durable physical medium customarily used for software interchange, for
235 | a price no more than your reasonable cost of physically performing this conveying of
236 | source, or (2) access to copy the Corresponding Source from a network server at no
237 | charge.
238 | * c) Convey individual copies of the object code with a copy of the written offer to
239 | provide the Corresponding Source. This alternative is allowed only occasionally and
240 | noncommercially, and only if you received the object code with such an offer, in
241 | accord with subsection 6b.
242 | * d) Convey the object code by offering access from a designated place (gratis or for
243 | a charge), and offer equivalent access to the Corresponding Source in the same way
244 | through the same place at no further charge. You need not require recipients to copy
245 | the Corresponding Source along with the object code. If the place to copy the object
246 | code is a network server, the Corresponding Source may be on a different server
247 | (operated by you or a third party) that supports equivalent copying facilities,
248 | provided you maintain clear directions next to the object code saying where to find
249 | the Corresponding Source. Regardless of what server hosts the Corresponding Source,
250 | you remain obligated to ensure that it is available for as long as needed to satisfy
251 | these requirements.
252 | * e) Convey the object code using peer-to-peer transmission, provided you inform
253 | other peers where the object code and Corresponding Source of the work are being
254 | offered to the general public at no charge under subsection 6d.
255 |
256 | A separable portion of the object code, whose source code is excluded from the
257 | Corresponding Source as a System Library, need not be included in conveying the
258 | object code work.
259 |
260 | A “User Product” is either (1) a “consumer product”, which
261 | means any tangible personal property which is normally used for personal, family, or
262 | household purposes, or (2) anything designed or sold for incorporation into a
263 | dwelling. In determining whether a product is a consumer product, doubtful cases
264 | shall be resolved in favor of coverage. For a particular product received by a
265 | particular user, “normally used” refers to a typical or common use of
266 | that class of product, regardless of the status of the particular user or of the way
267 | in which the particular user actually uses, or expects or is expected to use, the
268 | product. A product is a consumer product regardless of whether the product has
269 | substantial commercial, industrial or non-consumer uses, unless such uses represent
270 | the only significant mode of use of the product.
271 |
272 | “Installation Information” for a User Product means any methods,
273 | procedures, authorization keys, or other information required to install and execute
274 | modified versions of a covered work in that User Product from a modified version of
275 | its Corresponding Source. The information must suffice to ensure that the continued
276 | functioning of the modified object code is in no case prevented or interfered with
277 | solely because modification has been made.
278 |
279 | If you convey an object code work under this section in, or with, or specifically for
280 | use in, a User Product, and the conveying occurs as part of a transaction in which
281 | the right of possession and use of the User Product is transferred to the recipient
282 | in perpetuity or for a fixed term (regardless of how the transaction is
283 | characterized), the Corresponding Source conveyed under this section must be
284 | accompanied by the Installation Information. But this requirement does not apply if
285 | neither you nor any third party retains the ability to install modified object code
286 | on the User Product (for example, the work has been installed in ROM).
287 |
288 | The requirement to provide Installation Information does not include a requirement to
289 | continue to provide support service, warranty, or updates for a work that has been
290 | modified or installed by the recipient, or for the User Product in which it has been
291 | modified or installed. Access to a network may be denied when the modification itself
292 | materially and adversely affects the operation of the network or violates the rules
293 | and protocols for communication across the network.
294 |
295 | Corresponding Source conveyed, and Installation Information provided, in accord with
296 | this section must be in a format that is publicly documented (and with an
297 | implementation available to the public in source code form), and must require no
298 | special password or key for unpacking, reading or copying.
299 |
300 | ### 7. Additional Terms.
301 |
302 | “Additional permissions” are terms that supplement the terms of this
303 | License by making exceptions from one or more of its conditions. Additional
304 | permissions that are applicable to the entire Program shall be treated as though they
305 | were included in this License, to the extent that they are valid under applicable
306 | law. If additional permissions apply only to part of the Program, that part may be
307 | used separately under those permissions, but the entire Program remains governed by
308 | this License without regard to the additional permissions.
309 |
310 | When you convey a copy of a covered work, you may at your option remove any
311 | additional permissions from that copy, or from any part of it. (Additional
312 | permissions may be written to require their own removal in certain cases when you
313 | modify the work.) You may place additional permissions on material, added by you to a
314 | covered work, for which you have or can give appropriate copyright permission.
315 |
316 | Notwithstanding any other provision of this License, for material you add to a
317 | covered work, you may (if authorized by the copyright holders of that material)
318 | supplement the terms of this License with terms:
319 |
320 | * a) Disclaiming warranty or limiting liability differently from the terms of
321 | sections 15 and 16 of this License; or
322 | * b) Requiring preservation of specified reasonable legal notices or author
323 | attributions in that material or in the Appropriate Legal Notices displayed by works
324 | containing it; or
325 | * c) Prohibiting misrepresentation of the origin of that material, or requiring that
326 | modified versions of such material be marked in reasonable ways as different from the
327 | original version; or
328 | * d) Limiting the use for publicity purposes of names of licensors or authors of the
329 | material; or
330 | * e) Declining to grant rights under trademark law for use of some trade names,
331 | trademarks, or service marks; or
332 | * f) Requiring indemnification of licensors and authors of that material by anyone
333 | who conveys the material (or modified versions of it) with contractual assumptions of
334 | liability to the recipient, for any liability that these contractual assumptions
335 | directly impose on those licensors and authors.
336 |
337 | All other non-permissive additional terms are considered “further
338 | restrictions” within the meaning of section 10. If the Program as you received
339 | it, or any part of it, contains a notice stating that it is governed by this License
340 | along with a term that is a further restriction, you may remove that term. If a
341 | license document contains a further restriction but permits relicensing or conveying
342 | under this License, you may add to a covered work material governed by the terms of
343 | that license document, provided that the further restriction does not survive such
344 | relicensing or conveying.
345 |
346 | If you add terms to a covered work in accord with this section, you must place, in
347 | the relevant source files, a statement of the additional terms that apply to those
348 | files, or a notice indicating where to find the applicable terms.
349 |
350 | Additional terms, permissive or non-permissive, may be stated in the form of a
351 | separately written license, or stated as exceptions; the above requirements apply
352 | either way.
353 |
354 | ### 8. Termination.
355 |
356 | You may not propagate or modify a covered work except as expressly provided under
357 | this License. Any attempt otherwise to propagate or modify it is void, and will
358 | automatically terminate your rights under this License (including any patent licenses
359 | granted under the third paragraph of section 11).
360 |
361 | However, if you cease all violation of this License, then your license from a
362 | particular copyright holder is reinstated (a) provisionally, unless and until the
363 | copyright holder explicitly and finally terminates your license, and (b) permanently,
364 | if the copyright holder fails to notify you of the violation by some reasonable means
365 | prior to 60 days after the cessation.
366 |
367 | Moreover, your license from a particular copyright holder is reinstated permanently
368 | if the copyright holder notifies you of the violation by some reasonable means, this
369 | is the first time you have received notice of violation of this License (for any
370 | work) from that copyright holder, and you cure the violation prior to 30 days after
371 | your receipt of the notice.
372 |
373 | Termination of your rights under this section does not terminate the licenses of
374 | parties who have received copies or rights from you under this License. If your
375 | rights have been terminated and not permanently reinstated, you do not qualify to
376 | receive new licenses for the same material under section 10.
377 |
378 | ### 9. Acceptance Not Required for Having Copies.
379 |
380 | You are not required to accept this License in order to receive or run a copy of the
381 | Program. Ancillary propagation of a covered work occurring solely as a consequence of
382 | using peer-to-peer transmission to receive a copy likewise does not require
383 | acceptance. However, nothing other than this License grants you permission to
384 | propagate or modify any covered work. These actions infringe copyright if you do not
385 | accept this License. Therefore, by modifying or propagating a covered work, you
386 | indicate your acceptance of this License to do so.
387 |
388 | ### 10. Automatic Licensing of Downstream Recipients.
389 |
390 | Each time you convey a covered work, the recipient automatically receives a license
391 | from the original licensors, to run, modify and propagate that work, subject to this
392 | License. You are not responsible for enforcing compliance by third parties with this
393 | License.
394 |
395 | An “entity transaction” is a transaction transferring control of an
396 | organization, or substantially all assets of one, or subdividing an organization, or
397 | merging organizations. If propagation of a covered work results from an entity
398 | transaction, each party to that transaction who receives a copy of the work also
399 | receives whatever licenses to the work the party's predecessor in interest had or
400 | could give under the previous paragraph, plus a right to possession of the
401 | Corresponding Source of the work from the predecessor in interest, if the predecessor
402 | has it or can get it with reasonable efforts.
403 |
404 | You may not impose any further restrictions on the exercise of the rights granted or
405 | affirmed under this License. For example, you may not impose a license fee, royalty,
406 | or other charge for exercise of rights granted under this License, and you may not
407 | initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging
408 | that any patent claim is infringed by making, using, selling, offering for sale, or
409 | importing the Program or any portion of it.
410 |
411 | ### 11. Patents.
412 |
413 | A “contributor” is a copyright holder who authorizes use under this
414 | License of the Program or a work on which the Program is based. The work thus
415 | licensed is called the contributor's “contributor version”.
416 |
417 | A contributor's “essential patent claims” are all patent claims owned or
418 | controlled by the contributor, whether already acquired or hereafter acquired, that
419 | would be infringed by some manner, permitted by this License, of making, using, or
420 | selling its contributor version, but do not include claims that would be infringed
421 | only as a consequence of further modification of the contributor version. For
422 | purposes of this definition, “control” includes the right to grant patent
423 | sublicenses in a manner consistent with the requirements of this License.
424 |
425 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license
426 | under the contributor's essential patent claims, to make, use, sell, offer for sale,
427 | import and otherwise run, modify and propagate the contents of its contributor
428 | version.
429 |
430 | In the following three paragraphs, a “patent license” is any express
431 | agreement or commitment, however denominated, not to enforce a patent (such as an
432 | express permission to practice a patent or covenant not to sue for patent
433 | infringement). To “grant” such a patent license to a party means to make
434 | such an agreement or commitment not to enforce a patent against the party.
435 |
436 | If you convey a covered work, knowingly relying on a patent license, and the
437 | Corresponding Source of the work is not available for anyone to copy, free of charge
438 | and under the terms of this License, through a publicly available network server or
439 | other readily accessible means, then you must either (1) cause the Corresponding
440 | Source to be so available, or (2) arrange to deprive yourself of the benefit of the
441 | patent license for this particular work, or (3) arrange, in a manner consistent with
442 | the requirements of this License, to extend the patent license to downstream
443 | recipients. “Knowingly relying” means you have actual knowledge that, but
444 | for the patent license, your conveying the covered work in a country, or your
445 | recipient's use of the covered work in a country, would infringe one or more
446 | identifiable patents in that country that you have reason to believe are valid.
447 |
448 | If, pursuant to or in connection with a single transaction or arrangement, you
449 | convey, or propagate by procuring conveyance of, a covered work, and grant a patent
450 | license to some of the parties receiving the covered work authorizing them to use,
451 | propagate, modify or convey a specific copy of the covered work, then the patent
452 | license you grant is automatically extended to all recipients of the covered work and
453 | works based on it.
454 |
455 | A patent license is “discriminatory” if it does not include within the
456 | scope of its coverage, prohibits the exercise of, or is conditioned on the
457 | non-exercise of one or more of the rights that are specifically granted under this
458 | License. You may not convey a covered work if you are a party to an arrangement with
459 | a third party that is in the business of distributing software, under which you make
460 | payment to the third party based on the extent of your activity of conveying the
461 | work, and under which the third party grants, to any of the parties who would receive
462 | the covered work from you, a discriminatory patent license (a) in connection with
463 | copies of the covered work conveyed by you (or copies made from those copies), or (b)
464 | primarily for and in connection with specific products or compilations that contain
465 | the covered work, unless you entered into that arrangement, or that patent license
466 | was granted, prior to 28 March 2007.
467 |
468 | Nothing in this License shall be construed as excluding or limiting any implied
469 | license or other defenses to infringement that may otherwise be available to you
470 | under applicable patent law.
471 |
472 | ### 12. No Surrender of Others' Freedom.
473 |
474 | If conditions are imposed on you (whether by court order, agreement or otherwise)
475 | that contradict the conditions of this License, they do not excuse you from the
476 | conditions of this License. If you cannot convey a covered work so as to satisfy
477 | simultaneously your obligations under this License and any other pertinent
478 | obligations, then as a consequence you may not convey it at all. For example, if you
479 | agree to terms that obligate you to collect a royalty for further conveying from
480 | those to whom you convey the Program, the only way you could satisfy both those terms
481 | and this License would be to refrain entirely from conveying the Program.
482 |
483 | ### 13. Use with the GNU Affero General Public License.
484 |
485 | Notwithstanding any other provision of this License, you have permission to link or
486 | combine any covered work with a work licensed under version 3 of the GNU Affero
487 | General Public License into a single combined work, and to convey the resulting work.
488 | The terms of this License will continue to apply to the part which is the covered
489 | work, but the special requirements of the GNU Affero General Public License, section
490 | 13, concerning interaction through a network will apply to the combination as such.
491 |
492 | ### 14. Revised Versions of this License.
493 |
494 | The Free Software Foundation may publish revised and/or new versions of the GNU
495 | General Public License from time to time. Such new versions will be similar in spirit
496 | to the present version, but may differ in detail to address new problems or concerns.
497 |
498 | Each version is given a distinguishing version number. If the Program specifies that
499 | a certain numbered version of the GNU General Public License “or any later
500 | version” applies to it, you have the option of following the terms and
501 | conditions either of that numbered version or of any later version published by the
502 | Free Software Foundation. If the Program does not specify a version number of the GNU
503 | General Public License, you may choose any version ever published by the Free
504 | Software Foundation.
505 |
506 | If the Program specifies that a proxy can decide which future versions of the GNU
507 | General Public License can be used, that proxy's public statement of acceptance of a
508 | version permanently authorizes you to choose that version for the Program.
509 |
510 | Later license versions may give you additional or different permissions. However, no
511 | additional obligations are imposed on any author or copyright holder as a result of
512 | your choosing to follow a later version.
513 |
514 | ### 15. Disclaimer of Warranty.
515 |
516 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
517 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
518 | PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER
519 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
520 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
521 | QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
522 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
523 |
524 | ### 16. Limitation of Liability.
525 |
526 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
527 | COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS
528 | PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
529 | INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
530 | PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE
531 | OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
532 | WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
533 | POSSIBILITY OF SUCH DAMAGES.
534 |
535 | ### 17. Interpretation of Sections 15 and 16.
536 |
537 | If the disclaimer of warranty and limitation of liability provided above cannot be
538 | given local legal effect according to their terms, reviewing courts shall apply local
539 | law that most closely approximates an absolute waiver of all civil liability in
540 | connection with the Program, unless a warranty or assumption of liability accompanies
541 | a copy of the Program in return for a fee.
542 |
543 | END OF TERMS AND CONDITIONS
544 |
545 | ## How to Apply These Terms to Your New Programs
546 |
547 | If you develop a new program, and you want it to be of the greatest possible use to
548 | the public, the best way to achieve this is to make it free software which everyone
549 | can redistribute and change under these terms.
550 |
551 | To do so, attach the following notices to the program. It is safest to attach them
552 | to the start of each source file to most effectively state the exclusion of warranty;
553 | and each file should have at least the “copyright” line and a pointer to
554 | where the full notice is found.
555 |
556 |
557 | Copyright (C)
558 |
559 | This program is free software: you can redistribute it and/or modify
560 | it under the terms of the GNU General Public License as published by
561 | the Free Software Foundation, either version 3 of the License, or
562 | (at your option) any later version.
563 |
564 | This program is distributed in the hope that it will be useful,
565 | but WITHOUT ANY WARRANTY; without even the implied warranty of
566 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
567 | GNU General Public License for more details.
568 |
569 | You should have received a copy of the GNU General Public License
570 | along with this program. If not, see .
571 |
572 | Also add information on how to contact you by electronic and paper mail.
573 |
574 | If the program does terminal interaction, make it output a short notice like this
575 | when it starts in an interactive mode:
576 |
577 | Copyright (C)
578 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
579 | This is free software, and you are welcome to redistribute it
580 | under certain conditions; type `show c' for details.
581 |
582 | The hypothetical commands `show w' and `show c' should show the appropriate parts of
583 | the General Public License. Of course, your program's commands might be different;
584 | for a GUI interface, you would use an “about box”.
585 |
586 | You should also get your employer (if you work as a programmer) or school, if any, to
587 | sign a “copyright disclaimer” for the program, if necessary. For more
588 | information on this, and how to apply and follow the GNU GPL, see
589 | <>.
590 |
591 | The GNU General Public License does not permit incorporating your program into
592 | proprietary programs. If your program is a subroutine library, you may consider it
593 | more useful to permit linking proprietary applications with the library. If this is
594 | what you want to do, use the GNU Lesser General Public License instead of this
595 | License. But first, please read
596 | <>.
597 |
--------------------------------------------------------------------------------
/mctools/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajjackson/mctools/21b331d144e884bf0a5e91cb21232310f664607f/mctools/__init__.py
--------------------------------------------------------------------------------
/mctools/generic/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajjackson/mctools/21b331d144e884bf0a5e91cb21232310f664607f/mctools/generic/__init__.py
--------------------------------------------------------------------------------
/mctools/generic/fold_prim.py:
--------------------------------------------------------------------------------
1 | """Get primitive cell from supercell"""
2 | from argparse import ArgumentParser
3 | from os.path import isfile
4 | from json import loads
5 | from ase import Atoms
6 | import ase.io
7 | from numpy import matrix
8 | from numpy.linalg import inv
9 |
10 |
11 | def fold_prim(supercell_file, supercell_matrix, output='prim_cell_lattice.in'):
12 | """Get a primitive cell corresponding to a supercell
13 |
14 | Args:
15 | supercell_file (str): Path to supercell structure file. This should be
16 | a format recognised by ASE.
17 | supercell_matrix (str): Supercell expansion of the primitive cell. This
18 | is a 3x3 matrix, which can be expressed as a string with the format
19 | "[[ax, ay, az], [bx, by, bz], [cx, cy, cz]]" or without punctuation
20 | as "ax ay az bx by bz cx cy cz" or a path to an atat str file in
21 | which case lines 4-6 will be read in as a 3x3 matrix.
22 | output (str): Filename for output of dummy structure with correct
23 | lattice vectors. If None, do not write file.
24 |
25 | Returns:
26 | ase.Atoms:
27 | dummy structure with correct lattice vectors
28 | """
29 |
30 | r_supercell = matrix(ase.io.read(supercell_file).cell)
31 |
32 | if isfile(supercell_matrix):
33 | with open(supercell_matrix, 'r', encoding="utf-8") as f:
34 | for i in range(3):
35 | f.readline()
36 | rows = [f.readline() for i in range(3)]
37 |
38 | supercell_matrix = [[float(x) for x in row.split()] for row in rows]
39 | supercell_matrix = matrix(supercell_matrix)
40 | print(supercell_matrix)
41 |
42 | elif '[' in supercell_matrix:
43 | supercell_matrix = matrix(loads(supercell_matrix))
44 |
45 | else:
46 | supercell_matrix = [float(x) for x in supercell_matrix.split()]
47 | assert len(supercell_matrix) == 9
48 | supercell_matrix = matrix(supercell_matrix)
49 | supercell_matrix = supercell_matrix.reshape((3, 3))
50 |
51 | new_cell = inv(supercell_matrix) * r_supercell
52 |
53 | atoms = Atoms('X', cell=new_cell)
54 |
55 | if output is not None:
56 | ase.io.write(output, atoms, format='vasp', vasp5=True)
57 |
58 | return atoms
59 |
60 |
61 | def main(): # pylint: disable=missing-function-docstring
62 | parser = ArgumentParser(description="""
63 | Get a dummy primitive cell, given a supercell structure and matrix.
64 | The purpose of this is to set up calculations with BANDUP, which may
65 | require a primitive cell for a disordered phase. The given supercell
66 | matrix is inverted to obtain appropriate lattice vectors for the
67 | development of a k-point path.
68 | """)
69 |
70 | parser.add_argument('file', type=str,
71 | help="Structure file for relaxed supercell")
72 | parser.add_argument(
73 | 'matrix', type=str,
74 | help="""Supercell matrix. Either provide a path to an ATAT structure
75 | file, or provide matrix as a quoted string in form
76 | '[[ax, ay, az], [bx, by, bz], [cx, cy, cz]]'
77 | or 'ax ay az bx by bz cx cy cz' """)
78 | parser.add_argument('-o', '--output', type=str,
79 | default='prim_cell_lattice.in',
80 | help="Path for output file in VASP format.")
81 |
82 | args = parser.parse_args()
83 |
84 | fold_prim(supercell_file=args.file,
85 | supercell_matrix=args.matrix,
86 | output=args.output)
87 |
--------------------------------------------------------------------------------
/mctools/generic/get_energy.py:
--------------------------------------------------------------------------------
1 | from argparse import ArgumentParser
2 | from typing import List, Optional
3 |
4 | import ase.io
5 |
6 |
7 | def get_energy(filename):
8 | """Wrap ASE to get calculated energy from output file"""
9 | atoms = ase.io.read(filename)
10 | return atoms.get_total_energy()
11 |
12 |
13 | def main(params: Optional[List[str]] = None):
14 | """Get calculated energy from output file using ASE"""
15 |
16 | parser = ArgumentParser(description="Read energy from output")
17 | parser.add_argument("filename", type=str, nargs='?',
18 | default="vasprun.xml",
19 | help="Path to ab initio output file")
20 |
21 | if params:
22 | args = parser.parse_args(params)
23 | else:
24 | args = parser.parse_args()
25 |
26 | energy = get_energy(args.filename)
27 | print(energy)
28 |
29 |
30 | if __name__ == '__main__':
31 | main()
32 |
--------------------------------------------------------------------------------
/mctools/generic/get_minimum.py:
--------------------------------------------------------------------------------
1 | import argparse
2 | import ase.io
3 |
4 |
5 | def main():
6 | parser = argparse.ArgumentParser(
7 | description="Get the minimum-energy structure from a trajectory")
8 | parser.add_argument(
9 | 'input_file',
10 | type=str,
11 | default='POSCAR',
12 | help="Path to crystal structure file, recognisable by ASE")
13 | parser.add_argument(
14 | '--input_format',
15 | type=str,
16 | help="Format for input file (needed if ASE can't guess from filename)")
17 | parser.add_argument(
18 | '-o', '--output_file', default='POSCAR.min',
19 | help="Path/filename for output")
20 | parser.add_argument(
21 | '--output_format',
22 | type=str,
23 | help="Format for input file (needed if ASE can't guess from filename)")
24 | args = parser.parse_args()
25 | get_minimum(**vars(args))
26 |
27 |
28 | def get_minimum(input_file='POSCAR',
29 | input_format=None,
30 | output_file=None,
31 | output_format=None):
32 | try:
33 | if input_format is None:
34 | traj = ase.io.read(input_file, index=':')
35 | else:
36 | traj = ase.io.read(input_file, index=':', format=input_format)
37 | except IOError as e:
38 | raise Exception("I/O error({0}): {1}".format(e.errno, e.strerror))
39 |
40 | atoms = min(traj, key=(lambda a: a.get_total_energy()))
41 |
42 | if output_format is None:
43 | try:
44 | atoms.write(output_file, vasp5=True, direct=True)
45 | except TypeError:
46 | atoms.write(output_file)
47 | elif output_format == "vasp":
48 | atoms.write(output_file, format="vasp", vasp5=True, direct=True)
49 | else:
50 | atoms.write(output_file, format=output_format)
51 |
--------------------------------------------------------------------------------
/mctools/generic/get_primitive.py:
--------------------------------------------------------------------------------
1 | """Get primitive cell from crystal structure using spglib"""
2 |
3 | from argparse import ArgumentParser
4 | from pathlib import Path
5 | from typing import Any, Dict, List, Optional
6 |
7 | import ase
8 | import ase.io
9 | import spglib
10 |
11 |
12 | def get_parser() -> ArgumentParser:
13 | parser = ArgumentParser(
14 | description="Find a primitive unit cell using spglib")
15 | parser.add_argument(
16 | "input_file",
17 | type=Path,
18 | default="POSCAR",
19 | help="Path to crystal structure file, recognisable by ASE",
20 | )
21 | parser.add_argument(
22 | "--input-format",
23 | dest="input_format",
24 | type=str,
25 | help="Format for input file (needed if ASE can't guess from filename)",
26 | )
27 | parser.add_argument(
28 | "-t",
29 | "--threshold",
30 | type=float,
31 | default=1e-05,
32 | help=(
33 | "Distance threshold in AA for symmetry reduction "
34 | "(corresponds to spglib 'symprec' keyword)"
35 | ),
36 | )
37 | parser.add_argument(
38 | "-a",
39 | "--angle-tolerance",
40 | dest="angle_tolerance",
41 | type=float,
42 | default=-1.0,
43 | help="Angle tolerance for symmetry reduction",
44 | )
45 | parser.add_argument(
46 | "-o",
47 | "--output-file",
48 | type=Path,
49 | default=None,
50 | dest="output_file",
51 | help="Path/filename for output",
52 | )
53 | parser.add_argument(
54 | "--output-format",
55 | dest="output_format",
56 | type=str,
57 | default=None,
58 | help="Format for input file (needed if ASE can't guess from filename)",
59 | )
60 | parser.add_argument(
61 | "-v",
62 | "--verbose",
63 | action="store_true",
64 | help="Print output to screen even when writing to file.",
65 | )
66 | parser.add_argument(
67 | "-p",
68 | "--precision",
69 | type=int,
70 | help=("Number of decimal places for float display. "
71 | "(Output files are not affected)"),
72 | default=6,
73 | )
74 | return parser
75 |
76 |
77 | def main(params: Optional[List[str]] = None):
78 | parser = get_parser()
79 |
80 | if params:
81 | args = parser.parse_args(params)
82 | else:
83 | args = parser.parse_args()
84 |
85 | get_primitive(**snake_case_args(vars(args)))
86 |
87 |
88 | def snake_case_args(kwarg_dict: Dict[str, Any]) -> Dict[str, Any]:
89 | """Convert user-friendly hyphenated arguments to python_friendly ones"""
90 | return {key.replace("-", "_"): value for key, value in kwarg_dict.items()}
91 |
92 |
93 | def get_primitive_atoms(
94 | atoms: ase.Atoms,
95 | threshold: float = 1e-5,
96 | angle_tolerance: float = -1.0,
97 | print_spacegroup: bool = False,
98 | ) -> ase.Atoms:
99 | """Convert ASE Atoms to primitive cell using spglib"""
100 | atoms_spglib = (
101 | atoms.cell.array,
102 | atoms.get_scaled_positions(),
103 | atoms.numbers,
104 | )
105 |
106 | spacegroup = spglib.get_spacegroup(
107 | atoms_spglib, symprec=threshold, angle_tolerance=angle_tolerance)
108 | if print_spacegroup:
109 | print(f"Space group: {spacegroup}")
110 |
111 | cell, positions, atomic_numbers = spglib.find_primitive(
112 | atoms_spglib, symprec=threshold, angle_tolerance=angle_tolerance)
113 |
114 | primitive_atoms = ase.Atoms(
115 | scaled_positions=positions,
116 | cell=cell,
117 | numbers=atomic_numbers,
118 | pbc=True)
119 |
120 | return primitive_atoms
121 |
122 |
123 | def get_primitive(input_file: Path = Path('POSCAR'),
124 | input_format: Optional[str] = None,
125 | output_file: Optional[Path] = None,
126 | output_format: Optional[str] = None,
127 | threshold: float = 1e-5,
128 | angle_tolerance: float = -1.,
129 | verbose: bool = False,
130 | precision: int = 6) -> None:
131 |
132 | if output_file is None:
133 | verbose = True
134 |
135 | float_format_str = f"{{:{precision+4}.{precision}f}}"
136 |
137 | def format_float(x: float) -> str:
138 | return float_format_str.format(x)
139 |
140 | atoms = ase.io.read(input_file, format=input_format)
141 | atoms = get_primitive_atoms(
142 | atoms, threshold=threshold, angle_tolerance=angle_tolerance, print_spacegroup=verbose
143 | )
144 |
145 | if verbose:
146 | print("Primitive cell vectors:")
147 | for row in atoms.cell:
148 | print(" ".join(map(format_float, row)))
149 |
150 | print("Atomic positions and proton numbers:")
151 | for position, number in zip(atoms.get_scaled_positions(), atoms.numbers):
152 | print(" ".join(map(format_float, position)) + f"\t{number}")
153 |
154 | if output_file is None:
155 | pass
156 | else:
157 |
158 | atoms.write(output_file, format=output_format)
159 |
--------------------------------------------------------------------------------
/mctools/generic/get_spacegroup.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import argparse
4 | from pathlib import Path
5 | from typing import Optional
6 |
7 | import ase.io
8 | import spglib
9 |
10 |
11 | def get_default_file() -> Path:
12 | for candidate in ("geometry.in", "POSCAR", "castep.cell"):
13 | if (structure_file := Path.cwd() / candidate).is_file():
14 | return structure_file
15 |
16 | raise ValueError("Input file not specified, no default found.")
17 |
18 |
19 | def get_spacegroup(filename: Optional[Path] = None,
20 | filetype: Optional[str] = None):
21 |
22 | if filename is None:
23 | filename = get_default_file()
24 |
25 | atoms = ase.io.read(str(filename), format=filetype)
26 | cell = (atoms.cell.array, atoms.get_scaled_positions(), atoms.numbers)
27 |
28 | print("| Threshold / Å | Space group |")
29 | print("|---------------|-------------------|")
30 |
31 | for threshold in (1e-5, 1e-4, 5e-4, 1e-3, 5e-3, 1e-2, 5e-2, 1e-1):
32 | print("| {0:0.5f} | {1: <16} |".format(
33 | threshold, spglib.get_spacegroup(cell, symprec=threshold)))
34 |
35 |
36 | def main():
37 | parser = argparse.ArgumentParser()
38 | parser.add_argument("filename", type=Path, default=None, nargs="?",
39 | help="Input structure file")
40 | parser.add_argument("-f", "--filetype", type=str, default=None,
41 | help="File format for ASE importer")
42 | args = parser.parse_args()
43 | get_spacegroup(filename=args.filename, filetype=args.filetype)
44 |
--------------------------------------------------------------------------------
/mctools/generic/get_volume.py:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Copyright 2017 Adam Jackson
3 | ###############################################################################
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 | ###############################################################################
17 |
18 | import ase.io
19 | from argparse import ArgumentParser
20 |
21 |
22 | def get_volume(filename):
23 | atoms = ase.io.read(filename)
24 | return atoms.get_volume()
25 |
26 |
27 | def main():
28 | parser = ArgumentParser(description="Read volume from chemical structure")
29 | parser.add_argument("filename", type=str, nargs='?',
30 | default="geometry.in",
31 | help="Path to input file [default: ./geometry.in]")
32 |
33 | args = parser.parse_args()
34 |
35 | volume = get_volume(args.filename)
36 | print(volume)
37 |
--------------------------------------------------------------------------------
/mctools/generic/vectors.py:
--------------------------------------------------------------------------------
1 | # -*- encoding: utf-8 -*-
2 | """Get lattice vector in a, b, c, α, β, γ format from ase-compatible file"""
3 |
4 | ###############################################################################
5 | # Copyright 2015 Adam Jackson
6 | ###############################################################################
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | ###############################################################################
20 |
21 | from optparse import OptionParser
22 | import numpy as np
23 | import ase.io
24 |
25 |
26 | def main():
27 |
28 | parser = OptionParser()
29 | parser.add_option("-f", "--file",
30 | action="store", type="string", dest="input_file",
31 | default="geometry.in",
32 | help="Path to input file [default: ./geometry.in]")
33 | parser.add_option("-l", "--latex",
34 | action="store_true", dest="latex_format", default=False,
35 | help="""Print in convenient format for insertion in latex
36 | tabular environments""")
37 | parser.add_option("-p", "--precision", "--precision_length",
38 | action="store", type="int", dest="precision_length",
39 | default=3, help="""Number of decimal places to return
40 | (length in Angstroms)""")
41 | parser.add_option("-a", "--precision_angle",
42 | action="store", type="int", dest="precision_angle",
43 | default=2, help="""Number of decimal places to return
44 | (angle in degrees)""")
45 | # Add further options here
46 | (options, args) = parser.parse_args()
47 |
48 | # Read file and extract lattice vectors
49 | atoms = ase.io.read(options.input_file)
50 | lattice_matrix = np.array(atoms.get_cell())
51 |
52 | # Get lattice vector magnitudes (a, b, c) according to Pythagoras' theorem
53 | (a, b, c) = np.sqrt(np.sum(np.square(lattice_matrix), 1))
54 |
55 | # Calculate angles between vectors using relation
56 | # A.B = |A||B|cos(theta)
57 | gamma = np.arccos(lattice_matrix[0, :].dot(lattice_matrix[1, :])
58 | / (np.linalg.norm(lattice_matrix[0, :])
59 | * np.linalg.norm(lattice_matrix[1, :])))
60 |
61 | alpha = np.arccos(lattice_matrix[1, :].dot(lattice_matrix[2, :])
62 | / (np.linalg.norm(lattice_matrix[1, :])
63 | * np.linalg.norm(lattice_matrix[2, :])))
64 |
65 | beta = np.arccos(lattice_matrix[2, :].dot(lattice_matrix[0, :])
66 | / (np.linalg.norm(lattice_matrix[2, :])
67 | * np.linalg.norm(lattice_matrix[0, :])))
68 |
69 | # Convert to degrees
70 | (alpha, beta, gamma) = np.array([alpha, beta, gamma]).dot(180/np.pi)
71 |
72 | if options.latex_format:
73 | print('{0:6.{6}f}&{1:6.{6}f}&{2:6.{6}f}&{3:6.{7}f}&'
74 | '{4:6.{7}f}&{5:6.{7}f}'.format(a, b, c, alpha, beta, gamma,
75 | options.precision_length,
76 | options.precision_angle))
77 | else:
78 | print(' a {0}b {0}c {0}alpha{1}beta{1} gamma'.format(
79 | options.precision_length*" ", options.precision_angle*" "))
80 | print('{0:.{6}f} {1:.{6}f} {2:.{6}f} {3:.{7}f} {4:.{7}f} '
81 | '{5:.{7}f}'.format(a, b, c, alpha, beta, gamma,
82 | options.precision_length,
83 | options.precision_angle))
84 |
--------------------------------------------------------------------------------
/mctools/mace/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajjackson/mctools/21b331d144e884bf0a5e91cb21232310f664607f/mctools/mace/__init__.py
--------------------------------------------------------------------------------
/mctools/mace/tail_mace_fit.py:
--------------------------------------------------------------------------------
1 | """Realtime visualisation of fitting progress for MACE potential"""
2 | from argparse import ArgumentParser
3 | import os
4 | from pathlib import Path
5 | import re
6 | import subprocess
7 |
8 | import asciichartpy
9 |
10 |
11 | FLOAT = r"-?\d+\.\d+"
12 | EPOCH_RE = (rf".*Epoch (\d+): loss=({FLOAT}), "
13 | rf"RMSE_E_per_atom=({FLOAT}) meV, RMSE_F=({FLOAT}) meV / A.*")
14 | PLOT_CFG = {'height': 10, 'colors': [asciichartpy.blue]}
15 |
16 |
17 | def main():
18 | """Realtime visualisation of fitting progress for MACE potential"""
19 | parser = ArgumentParser()
20 | parser.add_argument("logfile", type=Path, help="Path to MACE training log")
21 | parser.add_argument("--buffer", type=int, default=100, help="Max steps to show")
22 | args = parser.parse_args()
23 |
24 |
25 | epoch_re = re.compile(EPOCH_RE)
26 |
27 | epochs, losses, energies, forces = [], [], [], []
28 |
29 | with subprocess.Popen(['tail', '-n', str(args.buffer), '-F', args.logfile],
30 | stdout=subprocess.PIPE,
31 | stderr=subprocess.PIPE) as tail_process:
32 | for line in tail_process.stdout:
33 | if (match := epoch_re.match(line.decode())):
34 | epoch, loss, energy, force = match.groups()
35 |
36 | epochs.append(int(epoch))
37 | losses.append(float(loss))
38 | energies.append(float(energy))
39 | forces.append(float(force))
40 |
41 | os.system("clear")
42 | epoch_slice = epochs[-args.buffer:]
43 | print(f"Epochs {epoch_slice[0]}-{epoch_slice[-1]}")
44 |
45 | for title, data in [(f"Loss {losses[-1]}", losses),
46 | (f"Energy/atom RMSE (meV) {energies[-1]}", energies),
47 | (f"Force RMSE (meV / A) {forces[-1]}", forces)]:
48 |
49 | print(f"\n{title}")
50 | print(asciichartpy.plot(data[-args.buffer:], PLOT_CFG))
51 |
52 | else:
53 | pass
54 |
--------------------------------------------------------------------------------
/mctools/other/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajjackson/mctools/21b331d144e884bf0a5e91cb21232310f664607f/mctools/other/__init__.py
--------------------------------------------------------------------------------
/mctools/other/plot_cplap_ternary.py:
--------------------------------------------------------------------------------
1 | from argparse import ArgumentParser
2 | import re
3 | from collections import OrderedDict
4 | from math import ceil
5 | import numpy as np
6 | from scipy.spatial import ConvexHull
7 | import matplotlib
8 | import matplotlib.pyplot as plt
9 | from matplotlib.patches import Polygon
10 | from matplotlib.gridspec import GridSpec
11 |
12 |
13 | def main():
14 | parser = ArgumentParser(
15 | description="Plot a ternary system from CPLAP outputs")
16 | parser.add_argument('-o', '--output', type=str, default=None,
17 | help='Output plot filename. Default: plot to screen')
18 | parser.add_argument('-g', '--grid-file', type=str, default='grid.dat',
19 | dest='grid_file',
20 | help='Path to grid.dat file from CPLAP')
21 | parser.add_argument('-t', '--txt-file', type=str, default='2Dplot.txt',
22 | dest='txt_file',
23 | help='Path to 2Dplot.txt file from CPLAP')
24 | parser.add_argument('--xmin', type=float, default=None,
25 | help='x-axis lower limit')
26 | parser.add_argument('--ymin', type=float, default=None,
27 | help='y-axis lower limit')
28 | parser.add_argument('--style', type=str, nargs='+', default=['ggplot'],
29 | help=('Path to Matplotlib style file(s) and/or name(s)'
30 | ' of inbuilt styles.'))
31 | parser.add_argument('--cmap', type=str, default='viridis',
32 | help=('Matplotlib colormap'))
33 | parser.add_argument('--width', type=float, default=6)
34 | parser.add_argument('--height', type=float, default=4)
35 | parser.add_argument('--ratio', type=int, nargs='+', default=[4],
36 | help=('Fraction of width occupied by plot vs colorbar:'
37 | ' give one or two integers. E.g. --ratio 4 gives'
38 | ' 4:1 ratio, --ratio 7 3 gives 7:3 ratio. '
39 | 'You may need to tune this when using --width.'))
40 | group = parser.add_mutually_exclusive_group()
41 | group.add_argument('--gridlines', action='store_true',
42 | dest='gridlines', default=None)
43 | group.add_argument('--no-gridlines', action='store_false',
44 | dest='gridlines')
45 | args = parser.parse_args()
46 | plot_cplap_ternary(**vars(args))
47 |
48 |
49 | def plot_cplap_ternary(output='plot-2d.pdf',
50 | grid_file='grid.dat', txt_file='2Dplot.txt',
51 | xmin=None, ymin=None,
52 | style=['ggplot'], cmap='viridis',
53 | width=6, height=4, ratio=[4],
54 | gridlines=None):
55 | # Set Truetype PDF/PS fonts unless overruled by style file
56 | matplotlib.rcParams['pdf.fonttype'] = 42
57 | matplotlib.rcParams['ps.fonttype'] = 42
58 | if len(style) > 0:
59 | matplotlib.style.use(style)
60 |
61 | fig = plt.figure(figsize=(width, height))
62 |
63 | if len(ratio) == 1:
64 | ratio += [1]
65 | elif len(ratio) > 2:
66 | raise ValueError('Ratio can be given as one or two integers. '
67 | '{} is too many!'.format(len(ratio)))
68 | gs = GridSpec(1, ratio[0] + ratio[1])
69 | ax = fig.add_subplot(gs.new_subplotspec((0, ratio[1]), colspan=ratio[0]))
70 | cax = fig.add_subplot(gs.new_subplotspec((0, 0), colspan=ratio[1]))
71 |
72 | with open(grid_file, 'rt') as f:
73 |
74 | # Scroll to formula and read
75 | for _ in range(3):
76 | line = f.readline()
77 | el_matches = re.findall(r'\d+ (\w+)', line)
78 |
79 | # Scroll to number of points and read
80 | for _ in range(4):
81 | line = f.readline()
82 | npts = 5
83 | npts_matches = re.findall(r'first\s+(\d+) points', line)
84 |
85 | if len(npts_matches) == 1:
86 | npts = int(npts_matches[0])
87 | else:
88 | raise Exception("Couldn't read number of polyhedron corners")
89 |
90 | # Scroll to data lines and read coordinates from npts lines
91 | for _ in range(5):
92 | f.readline()
93 | region = np.zeros((npts, 2))
94 |
95 | for i in range(npts):
96 | line = f.readline().split()
97 | x, y = float(line[0]), float(line[1])
98 | region[i, :] = x, y
99 |
100 | # # Use convex hull solver to draw polyhedron edges in correct order
101 | # hull = np.array([region[i] for i in ConvexHull(region).vertices])
102 | # region_patch = Polygon(hull, facecolor=(0.6, 0.6, 0.6))
103 | # ax.add_patch(region_patch)
104 |
105 | # Read in rest of mesh, skipping header, region and '|' column
106 | mesh = np.genfromtxt('grid.dat', skip_header=(12 + npts),
107 | usecols=(0, 1, 3))
108 | mesh_x = sorted(set(mesh[:, 0]))
109 | mesh_y = sorted(set(mesh[:, 1]))
110 | mesh_z = np.zeros((len(mesh_y), len(mesh_x))) * np.NaN
111 | for x, y, z in mesh:
112 | ix = mesh_x.index(x)
113 | iy = mesh_y.index(y)
114 | mesh_z[iy, ix] = z
115 | mesh_z = np.ma.masked_invalid(mesh_z)
116 | dep_mu = ax.pcolormesh(mesh_x, mesh_y, mesh_z, rasterized=True, cmap=cmap)
117 | cbar = fig.colorbar(dep_mu, cax=cax)
118 | cbar.set_label(r'$\mu$ ({}) / eV'.format(el_matches[2]))
119 |
120 | with open('2Dplot.txt', 'rt') as f:
121 | lines = f.readlines()
122 |
123 | data = OrderedDict()
124 |
125 | for i in range(len(lines) // 4 + 1):
126 | species = lines[i * 4][1:-1]
127 |
128 | x1, y1 = map(float, lines[i * 4 + 1].split())
129 | x2, y2 = map(float, lines[i * 4 + 2].split())
130 |
131 | data[species] = [[x1, x2], [y1, y2]]
132 |
133 | if xmin is None:
134 | xmin = ceil(min(min(coords[0]) for coords in data.values()))
135 | if ymin is None:
136 | ymin = ceil(min(min(coords[1]) for coords in data.values()))
137 |
138 | for species, (x, y) in data.items():
139 | ax.plot(x, y, '-', label=format_chem(species))
140 |
141 | ax.legend()
142 | ax.set_xlim(xmin, 0)
143 | ax.set_ylim(ymin, 0)
144 | ax.set_xlabel(r'$\mu$ ({}) / eV'.format(el_matches[0]))
145 | ax.xaxis.set_label_position('top')
146 | ax.xaxis.set_ticks_position('top')
147 | ax.set_ylabel(r'$\mu$ ({}) / eV'.format(el_matches[1]))
148 | ax.yaxis.set_label_position('right')
149 | ax.yaxis.set_ticks_position('right')
150 |
151 | # Gridlines option can overrule style defaults
152 | if gridlines is not None:
153 | ax.grid(gridlines)
154 |
155 | fig.tight_layout()
156 |
157 | if output is None:
158 | plt.show()
159 | else:
160 | fig.savefig(output)
161 |
162 |
163 | def format_chem(species):
164 | text = re.findall(r'\D+', species)
165 | nums = re.findall(r'\d+', species)
166 | chem = ''
167 | for t, n, in zip(text, nums):
168 | chem += t
169 | chem += r'$_{{{}}}$'.format(n)
170 | if len(text) > len(nums):
171 | chem += text[-1]
172 | return chem
173 |
174 | if __name__ == '__main__':
175 | main()
176 |
--------------------------------------------------------------------------------
/mctools/other/sendto.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env python
2 |
3 | import os
4 | from os.path import basename, dirname, abspath, join, isfile
5 | import argparse
6 |
7 | try:
8 | from configparser import ConfigParser
9 | except ImportError:
10 | from ConfigParser import ConfigParser
11 |
12 | import subprocess
13 |
14 |
15 | def sendto(server=False, project=False, folders=False, nw=False):
16 |
17 | if not server:
18 | raise Exception('No remote server defined')
19 |
20 | conf_file = join(os.environ['HOME'], '.sendto.conf')
21 | if not isfile(conf_file):
22 | raise Exception("No config file found. Server names should be "
23 | "set up with calculation directories "
24 | "in {0}".format(conf_file))
25 |
26 | conf = ConfigParser()
27 | conf.read(conf_file)
28 | rundir = conf.get(server, 'rundir')
29 |
30 | # Use current directory if none provided
31 | if len(folders) == 0:
32 | folders = ['os.path.curdir']
33 |
34 | for calc in folders:
35 | calc = abspath(calc)
36 | # If project isn't given use name of directory two levels
37 | # above (Assumes structure /parents/PROJECTS/runs/RUNDIRS)
38 | if not project:
39 | project = basename(dirname(dirname(calc)))
40 |
41 | rsync_call = ['rsync', '-avzu', calc,
42 | ':'.join((server, os.path.join(rundir,
43 | project)))]
44 |
45 | if nw:
46 | rsync_call += ['--exclude', 'WAVECAR',
47 | '--exclude', 'CHGCAR',
48 | '--exclude', 'CHG']
49 |
50 | subprocess.call(rsync_call)
51 |
52 |
53 | def get_args():
54 | parser = argparse.ArgumentParser(
55 | description="Send calculations folder(s) to remote server"
56 | )
57 | parser.add_argument('server', type=str,
58 | help="Server name from SSH config")
59 | parser.add_argument('-p', '--project', type=str, default=False,
60 | help="Project ID (guess if not provided)")
61 | parser.add_argument('--nw', '--no-wavecar', action='store_true',
62 | help="Don't include wavecar, chgcar, chg")
63 | parser.add_argument('folders', type=str, nargs='*')
64 | args = parser.parse_args()
65 | return vars(args)
66 |
67 |
68 | def main():
69 | args = get_args()
70 | sendto(**args)
71 |
72 | if __name__ == '__main__':
73 | main()
74 |
--------------------------------------------------------------------------------
/mctools/other/sqs_read.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env python
2 | from __future__ import print_function, absolute_import
3 |
4 | import argparse
5 | import numpy as np
6 | import ase.atoms
7 | import ase.build
8 | import ase.visualize
9 |
10 | def atoms_from_sqs(filename):
11 |
12 | with open(filename, 'r') as f:
13 | lines = f.readlines()
14 | lines = [line.split() for line in lines]
15 |
16 | basis = np.matrix([list(map(float, line)) for line in lines[:3]])
17 | scell = np.matrix([list(map(float, line)) for line in lines[3:6]])
18 |
19 | spositions = [np.matrix(list(map(float, line[:3]))) for line in lines[6:]]
20 | symbols = [line[-1] for line in lines[6:]]
21 |
22 | supercell = scell * basis
23 | positions = spositions * basis
24 | atoms = ase.atoms.Atoms(symbols=symbols,
25 | cell=supercell,
26 | positions=positions,
27 | pbc=True)
28 |
29 | return atoms
30 |
31 | def txt_display(atoms):
32 | print("Unit cell:")
33 | print(atoms.cell)
34 | print("Positions")
35 | atoms = ase.build.sort(atoms)
36 | for atom in atoms:
37 |
38 | print(atom.position, atom.symbol)
39 |
40 | def main():
41 | parser = argparse.ArgumentParser()
42 | parser.add_argument('filename', nargs='?', default='bestsqs.out',
43 | help="Input file generated by ATAT")
44 | parser.add_argument('--output', '-o', default=None,
45 | help="If specified, write to this filename")
46 | parser.add_argument('--gui', '-g', action='store_true',
47 | help="Show structure in ASE-GUI")
48 |
49 | args = parser.parse_args()
50 |
51 | atoms = atoms_from_sqs(args.filename)
52 |
53 | if args.output is not None:
54 | # Write file with vasp5 flag if supported
55 | try:
56 | atoms.write(args.output, sort=True, vasp5=True)
57 | except TypeError:
58 | atoms = ase.build.sort(atoms)
59 | atoms.write(args.output)
60 | else:
61 | txt_display(atoms)
62 |
63 | if args.gui:
64 | ase.visualize.view(atoms)
65 |
66 | if __name__ == '__main__':
67 | main()
68 |
--------------------------------------------------------------------------------
/mctools/phonon/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajjackson/mctools/21b331d144e884bf0a5e91cb21232310f664607f/mctools/phonon/__init__.py
--------------------------------------------------------------------------------
/mctools/phonon/phonon_dispersion_compare.py:
--------------------------------------------------------------------------------
1 | import sys
2 | from argparse import ArgumentParser
3 | from pathlib import Path
4 | from typing import List, Optional
5 |
6 | from euphonic import ForceConstants, ureg
7 | from euphonic.cli.utils import _bands_from_force_constants, load_data_from_file
8 | from euphonic.plot import plot_1d, plot_1d_to_axis
9 | from matplotlib import pyplot as plt
10 | from matplotlib.axes import Axes
11 |
12 |
13 | def get_parser() -> ArgumentParser:
14 | parser = ArgumentParser()
15 | parser.add_argument(
16 | "filenames", nargs="+", type=Path, help="Force constants data files"
17 | )
18 | parser.add_argument(
19 | "--labels",
20 | nargs="+",
21 | type=str,
22 | default=None,
23 | help="Labels corresponding to filenames",
24 | )
25 | parser.add_argument(
26 | "--save",
27 | type=Path,
28 | nargs='?',
29 | default=None,
30 | const="bands.pdf",
31 | help="Save figure to file",
32 | )
33 | parser.add_argument(
34 | "--title",
35 | type=str,
36 | default=None,
37 | help="Figure title"
38 | )
39 | parser.add_argument(
40 | "--legend-axis",
41 | dest="legend_axis",
42 | type=int,
43 | default=0,
44 | help=("Index for band segment with legend. "
45 | "(Use this when the first segment is short!)")
46 | )
47 | return parser
48 |
49 |
50 | def plot_bands(
51 | fc: ForceConstants, axes: Optional[List[Axes]], color="C0"
52 | ) -> List[Axes]:
53 | bands, x_tick_labels, split_args = _bands_from_force_constants(
54 | fc,
55 | q_distance=(0.01 * ureg("1/angstrom")),
56 | asr="reciprocal",
57 | dipole=True,
58 | )
59 | bands.reorder_frequencies()
60 | spectrum = bands.get_dispersion()
61 | spectrum.x_tick_labels = x_tick_labels
62 |
63 | if axes is None:
64 | # plot_1d creates a final invisible axis: the rest are
65 | # segments of the band structure.
66 | fig = plot_1d(spectrum.split(**split_args), color=color)
67 | axes = fig.axes[:-1]
68 | else:
69 | for ax, segment in zip(axes, spectrum.split(**split_args)):
70 | plot_1d_to_axis(segment, ax, color=color)
71 |
72 | return axes
73 |
74 |
75 | def main():
76 | args = get_parser().parse_args()
77 |
78 | data = [load_data_from_file(filename) for filename in args.filenames]
79 | for fc, filename in zip(data, args.filenames):
80 | if not isinstance(fc, ForceConstants):
81 | print(
82 | "Cannot use {filename}, this script only "
83 | "works with force constants"
84 | )
85 | sys.exit()
86 |
87 | axes = None
88 | for i, fc in enumerate(data):
89 | axes = plot_bands(fc, axes, color=f'C{i}')
90 |
91 | # There are a lot of lines, to get a sensible legend
92 | # we just label one per file
93 | nbands = int(len(axes[0].lines) / len(data))
94 | labels = args.labels if args.labels else [str(f) for f in args.filenames]
95 | axes[args.legend_axis].legend(axes[0].lines[::nbands], labels)
96 |
97 | fig = axes[0].get_figure()
98 | if args.title:
99 | fig.suptitle(args.title)
100 |
101 | if args.save:
102 | fig.savefig(args.save)
103 | else:
104 | plt.show()
105 |
--------------------------------------------------------------------------------
/mctools/vasp/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajjackson/mctools/21b331d144e884bf0a5e91cb21232310f664607f/mctools/vasp/__init__.py
--------------------------------------------------------------------------------
/mctools/vasp/get_vbm.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from __future__ import print_function, absolute_import
3 |
4 | try:
5 | from itertools import ifilter as filter
6 | except ImportError:
7 | pass
8 |
9 | import argparse
10 | try:
11 | import xml.etree.cElementTree as ET
12 | except ImportError:
13 | import xml.etree.ElementTree as ET
14 |
15 | def get_eigs(vasp_xml):
16 | """Read vasprun.xml file and get the eigenvalues
17 |
18 | Args:
19 | vasp_xml: path to "vasprun.xml" output file
20 | Returns:
21 | eig_sets: list of lists, grouped by k-point
22 | [[[kpt1_eig1 occ11], [kpt1_eig2, occ12]...]
23 | [[kpt2_eig1_occ21], [kpt2_eig2, occ22]...] ...]
24 |
25 | """
26 |
27 | tree = ET.ElementTree(file=vasp_xml)
28 |
29 | # Get last set of eigenvalues
30 | eigs = list(tree.iter(tag='eigenvalues'))[-1]
31 |
32 | type(eigs)
33 | eig_sets = [eig_set.getchildren()
34 | for eig_set in eigs.iter('set')
35 | if ('comment' in eig_set.attrib
36 | and 'kpoint' in eig_set.attrib['comment'])]
37 |
38 | def eig_set_to_lists(eig_set):
39 | return list(map(lambda el: list(map(float, el.text.split())), eig_set))
40 |
41 | eig_sets = list(map(eig_set_to_lists, eig_sets))
42 | return eig_sets
43 |
44 | def get_max_eig_from_xml(vasp_xml):
45 | """
46 | Read vasprun.xml and return highest occupied eigenvalue.
47 |
48 | If you included the right k-points this should be the VBM...
49 | """
50 | eigs = get_eigs(vasp_xml)
51 |
52 | # Flatten from grouping by k-points with this nasty
53 | # double list comprehension
54 |
55 | all_eigs = [eig for kpt_eigs in eigs for eig in kpt_eigs]
56 | occupied = filter(lambda x: x[1] > 0., all_eigs)
57 | return max(x[0] for x in occupied)
58 |
59 | def main():
60 | parser = argparse.ArgumentParser(
61 | description="Get the maximum occupied eigenvalue from a vasp run."
62 | )
63 | parser.add_argument("xml_file", nargs='?', default='vasprun.xml',
64 | help="Path to vasprun.xml file")
65 | args = parser.parse_args()
66 |
67 | print(get_max_eig_from_xml(args.xml_file))
68 |
69 | if __name__ == '__main__':
70 | main()
71 |
--------------------------------------------------------------------------------
/mctools/vasp/vasp_charge.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env python
2 |
3 | from __future__ import print_function, absolute_import, division
4 | import argparse
5 | import os
6 | from math import ceil
7 | import ase.io
8 |
9 | def get_neutral_electrons(atoms, pp='PBE', setups={}):
10 | """Get the number of valence electrons in a neutral structure
11 |
12 | A summary is printed to the standard output.
13 |
14 | Arguments:
15 |
16 | atoms (ase.Atoms): ASE Atoms object corresponding to VASP
17 | calculation
18 |
19 | pp (str): Specify the potpaw directory. The usual aliases (LDA,
20 | PBE, PW91) are available, or the full name
21 | (e.g. 'potpaw_PBE') can be used
22 |
23 | setups (dict): Special POTCAR identities specified per-species
24 | as a dict. e.g. {'O': '_pv'}
25 |
26 |
27 |
28 | """
29 | zvals = get_zval_dict(atoms, setups=setups, pp=pp)
30 |
31 | # Sum over atoms
32 | nelect = sum([zvals[el] for el in atoms.get_chemical_symbols()])
33 |
34 | return nelect
35 |
36 |
37 | def get_zval(potcar):
38 | """Read ZVAL from a POTCAR file"""
39 |
40 | with open(potcar, 'r') as f:
41 | for line in f:
42 | if 'ZVAL' in line:
43 | break
44 | else:
45 | raise Exception('No ZVAL found in file {0}'.format(potcar))
46 |
47 | line = line.strip()
48 | zval = line.split()[5].strip()
49 |
50 | return float(zval)
51 |
52 | def get_zval_dict(atoms, setups={}, pp='PBE'):
53 | """Set up a dictionary of ZVALs (default electron count)"""
54 |
55 | pp_aliases = {'LDA': 'potpaw',
56 | 'PBE': 'potpaw_PBE',
57 | 'PW91': 'potpaw_GGA'}
58 |
59 | if pp in pp_aliases:
60 | pp = pp_aliases[pp]
61 |
62 | pp_dir = os.path.join(os.environ['VASP_PP_PATH'], pp)
63 |
64 | elements = set(atoms.get_chemical_symbols())
65 | zvals = {}
66 | for element in elements:
67 | if element in setups:
68 | potcar_path = os.path.join(pp_dir,
69 | element + setups[element],
70 | 'POTCAR')
71 | else:
72 | potcar_path = os.path.join(pp_dir, element, 'POTCAR')
73 | zvals[element] = get_zval(potcar_path)
74 | return zvals
75 |
76 |
77 | def report(atoms, nelect, charge=0, setups={}, pp='PBE'):
78 | """Report stats from nelect, suggest numbers of bands"""
79 | nelect = nelect - charge
80 | zvals = get_zval_dict(atoms, setups=setups, pp=pp)
81 |
82 | formula_str = atoms.get_chemical_formula()
83 | print("Chemical formula: {0}".format(formula_str))
84 | for el, z in zvals.items():
85 | print("{0:3s}:{1:10.2f}".format(el, z))
86 |
87 | nbands_nospin = int(ceil(nelect / 2))
88 | print("")
89 | print("Total electrons: {0}".format(nelect))
90 | print("")
91 | print("Occupied bands for non-spin-polarised "
92 | "calc:{0:4d}".format(nbands_nospin))
93 | print("Suggested NBANDS for parallelism in:")
94 | for ppn in (8, 12, 16, 24):
95 | nbands = int(ceil((nbands_nospin + 4) / ppn) * ppn)
96 | print("{0:3}:{1:10}".format(ppn, nbands))
97 |
98 | def main():
99 | parser = argparse.ArgumentParser(
100 | description="Get the expected numbers of electrons and bands")
101 | parser.add_argument(
102 | 'input_file',
103 | type=str,
104 | default='POSCAR',
105 | help="Path to crystal structure file, recognisable by ASE")
106 | args = parser.parse_args()
107 |
108 | atoms = ase.io.read(args.input_file)
109 | nelect = get_neutral_electrons(atoms)
110 |
111 | report(atoms, nelect)
112 |
113 | if __name__ == '__main__':
114 | main()
115 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [build-system]
2 | requires = ["setuptools"]
3 | build-backend = "setuptools.build_meta"
4 |
5 | [project]
6 | name = "mctools"
7 | version = "1.1"
8 | authors = [
9 | {name = "Adam J. Jackson", email = "a.j.jackson@physics.org"},
10 | ]
11 | description = "Convenience tools for computational materials chemistry"
12 | keywords = ["chemistry", "ASE", "DFT"]
13 | license = {text = "GPL v3"}
14 | classifiers=[
15 | "Development Status :: 4 - Beta",
16 | "Intended Audience :: Science/Research",
17 | "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
18 | "Natural Language :: English",
19 | "Programming Language :: Python :: 3",
20 | "Topic :: Scientific/Engineering :: Chemistry",
21 | "Topic :: Scientific/Engineering :: Physics",
22 | ]
23 | requires-python = ">=3.9"
24 | dependencies = [
25 | "asciichartpy",
26 | "ase",
27 | "euphonic",
28 | "spglib",
29 | "matplotlib",
30 | ]
31 |
32 | [project.urls]
33 | Repository = "https://github.com/ajjackson/mctools"
34 |
35 | [tool.setuptools.dynamic]
36 | readme = {file = ["README.md"]}
37 |
38 | [tool.black]
39 | line-length = 79
40 |
41 | [project.scripts]
42 | fold-prim = "mctools.generic.fold_prim:main"
43 | get-energy = "mctools.generic.get_energy:main"
44 | get-minimum = "mctools.generic.get_minimum:main"
45 | get-primitive = "mctools.generic.get_primitive:main"
46 | get-spacegroup = "mctools.generic.get_spacegroup:main"
47 | get-vbm = "mctools.vasp.get_vbm:main"
48 | get-volume = "mctools.generic.get_volume:main"
49 | phonon-dispersion-compare = "mctools.phonon.phonon_dispersion_compare:main"
50 | plot-cplap-ternary = "mctools.other.plot_cplap_ternary:main"
51 | sqs-read = "mctools.other.sqs_read:main"
52 | sendto = "mctools.other.sendto:main"
53 | tail-mace-fit = "mctools.mace.tail_mace_fit:main"
54 | vasp-charge = "mctools.vasp.vasp_charge:main"
55 | vectors = "mctools.generic.vectors:main"
56 |
--------------------------------------------------------------------------------
/tests/test_get_energy.py:
--------------------------------------------------------------------------------
1 | import ase.build
2 | from ase.calculators.singlepoint import SinglePointCalculator
3 | import ase.io
4 | import pytest
5 |
6 | from mctools.generic.get_energy import get_energy, main
7 |
8 |
9 | ENERGY = 3.141
10 | FILENAME = "methane.extxyz"
11 |
12 |
13 | @pytest.fixture
14 | def methane_with_energy() -> ase.Atoms:
15 | atoms = ase.build.molecule("CH4")
16 | atoms.calc = SinglePointCalculator(atoms, energy=ENERGY)
17 | return atoms
18 |
19 |
20 | def test_get_energy(methane_with_energy, tmp_path) -> None:
21 | ase.io.write(tmp_path / FILENAME, methane_with_energy)
22 |
23 | assert get_energy(tmp_path / FILENAME) == pytest.approx(ENERGY)
24 |
25 |
26 | def test_main(methane_with_energy, tmp_path, capsys) -> None:
27 | ase.io.write(tmp_path / FILENAME, methane_with_energy)
28 |
29 | main([str(tmp_path / FILENAME)])
30 | captured = capsys.readouterr()
31 | assert float(captured.out) == pytest.approx(ENERGY)
32 |
--------------------------------------------------------------------------------
/tests/test_get_primitive.py:
--------------------------------------------------------------------------------
1 | import textwrap
2 |
3 | import ase
4 | import ase.build
5 | from numpy.random import RandomState
6 | import pytest
7 |
8 | from mctools.generic.get_primitive import main
9 |
10 |
11 | FILENAME = "rattled_cu.extxyz"
12 | OUTFILENAME = "POSCAR"
13 | REF_STDOUT = textwrap.dedent(
14 | """\
15 | Space group: Fm-3m (225)
16 | Primitive cell vectors:
17 | 0.000 1.805 1.805
18 | 1.805 0.000 1.805
19 | 1.805 1.805 0.000
20 | Atomic positions and proton numbers:
21 | 0.500 0.500 0.500\t29
22 | """
23 | )
24 | REF_POSCAR = textwrap.dedent(
25 | """\
26 | Cu
27 | 1.0000000000000000
28 | 0.0000000000000000 1.8050080045893520 1.8050080045893520
29 | 1.8050080045893520 0.0000000000000000 1.8050080045893520
30 | 1.8050080045893520 1.8050080045893520 0.0000000000000000
31 | Cu
32 | 1
33 | Cartesian
34 | 1.8050080045893520 1.8050080045893520 1.8050080045893520
35 | """ # noqa:W291
36 | )
37 |
38 |
39 | @pytest.fixture
40 | def rattled_cu() -> ase.Atoms:
41 | rng = RandomState(seed=1)
42 |
43 | atoms = ase.build.bulk("Cu", cubic=True) * (2, 2, 2)
44 | atoms.rattle(stdev=1e-3, seed=1)
45 | atoms.set_cell(atoms.cell.array + 1e-4 * rng.rand(3, 3))
46 |
47 | return atoms
48 |
49 |
50 | def test_get_primitive(rattled_cu, tmp_path, capsys) -> None:
51 | rattled_cu.write(tmp_path / FILENAME)
52 |
53 | main([str(tmp_path / FILENAME),
54 | "--input-format=extxyz",
55 | "--threshold=1e-2",
56 | "--angle-tolerance=1",
57 | "-o",
58 | str(tmp_path / OUTFILENAME),
59 | "-v",
60 | "--precision=3"
61 | ])
62 |
63 | captured = capsys.readouterr()
64 | assert captured.out == REF_STDOUT
65 |
66 | with open(tmp_path / OUTFILENAME, "r") as fd:
67 | assert fd.read() == REF_POSCAR
68 |
--------------------------------------------------------------------------------
/tests/test_get_spacegroup.py:
--------------------------------------------------------------------------------
1 | import textwrap
2 |
3 | import ase.build
4 | from numpy import logical_not
5 | from numpy.random import RandomState
6 | import pytest
7 |
8 | from mctools.generic.get_spacegroup import get_spacegroup
9 |
10 |
11 | FILENAME = "cu_rattled.extxyz"
12 |
13 | REF_TEXT = textwrap.dedent(
14 | """\
15 | | Threshold / Å | Space group |
16 | |---------------|-------------------|
17 | | 0.00001 | P1 (1) |
18 | | 0.00010 | P1 (1) |
19 | | 0.00050 | Pm (6) |
20 | | 0.00100 | Pm (6) |
21 | | 0.00500 | Pmc2_1 (26) |
22 | | 0.01000 | Fm-3m (225) |
23 | | 0.05000 | Fm-3m (225) |
24 | | 0.10000 | Fm-3m (225) |
25 | """
26 | )
27 |
28 |
29 | @pytest.fixture(scope="module")
30 | def symmetry_broken_cu() -> ase.Atoms:
31 | atoms = ase.build.bulk("Cu", cubic=True) * (2, 2, 2)
32 |
33 | rng = RandomState(seed=1)
34 |
35 | # Break symmetry by up to 0.01 on a mirror plane
36 | xy_plane = atoms.positions[:, 2] == 0.0
37 | atoms.positions[xy_plane, :2] += 5e-3 - 1e-2 * rng.rand(xy_plane.sum(), 2)
38 |
39 | # Break symmetry by up to 0.0001 elsewhere
40 | off_plane = logical_not(xy_plane)
41 | atoms.positions[off_plane] += 5e-5 - 1e-4 * rng.rand(off_plane.sum(), 3)
42 |
43 | return atoms
44 |
45 |
46 | def test_get_spacegroup(symmetry_broken_cu, tmp_path, capsys) -> None:
47 | symmetry_broken_cu.write(tmp_path / FILENAME)
48 | get_spacegroup(filename=str(tmp_path / FILENAME))
49 | captured = capsys.readouterr()
50 |
51 | assert captured.out == REF_TEXT
52 |
--------------------------------------------------------------------------------