├── Example └── POSCAR ├── LICENSE ├── Parsing-Hessian-matrix-from-vasprun ├── Example │ └── hessian.dat ├── Extract_hessian.py ├── README.md └── parsing hessian matrix ├── README.md ├── Thermal_properties_from_phonopy ├── extract_thermal_yaml.py └── thermal_properties.yaml ├── _config.yml ├── convert_ExcitingXml2Vasp.py ├── get_TotEle.py ├── get_forces_all_ionicSteps.py ├── get_properties_VASP.py └── src ├── Main_file.py ├── contcar_poscar.py ├── create_phonon_directories.py ├── elastic_constants.py ├── energy.py ├── evaluate_manually_Elastic_constants.py ├── fit_energy_vs_vol.py ├── poscar.py └── strain.py /Example/POSCAR: -------------------------------------------------------------------------------- 1 | Hf2 2 | 1.00000000000000 3 | 3.2034364762002947 0.0000000849104951 -0.0000000010327879 4 | -1.6017181638825977 2.7742573868598530 0.0000000025125482 5 | -0.0000000032264187 0.0000000021136038 5.0548251385690195 6 | Hf 7 | 2 8 | Direct 9 | 0.3333333018142252 0.6666666970392585 0.2500000000021482 10 | 0.6666666981857747 0.3333333029607416 0.7499999999978518 11 | 12 | 0.00000000E+00 0.00000000E+00 0.00000000E+00 13 | 0.00000000E+00 0.00000000E+00 0.00000000E+00 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Parsing-Hessian-matrix-from-vasprun/Extract_hessian.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import lxml 4 | from yaml import load, dump 5 | import sys, os, yaml 6 | #from lxml import etree 7 | import numpy as np 8 | from scipy import linalg as LA 9 | 10 | #*******************************DOCUMENTATION*********************************** 11 | # 12 | #AUTHOR : ASIF IQBAL BHATTI 13 | #CREATED ON : 09/02/2020 14 | #USAGE : To parse VASP vasprun.xml input file to extract Hessian Matrix 15 | #Output file has already been defined in the code (hessian.dat). 16 | #CAUTION: Use at your own risk (NOTEVEN IMPLIED GUARANTEED, WHATSOEVER), 17 | #the code has been tested but the user in the end will have to verify the ouput. 18 | #Xpath is useful tool for directly accessing the element in a Node 19 | # 20 | #-> CHECK this website for lxml introduccion: https://lxml.de/tutorial.html & 21 | #-> https://github.com/lxml/lxml 22 | # 23 | #************************END OF DOCUMENTATION*********************************** 24 | 25 | try: 26 | from lxml import etree 27 | print("running with lxml.etree") 28 | except ImportError: 29 | try: 30 | # Python 2.5 31 | import xml.etree.cElementTree as etree 32 | print("running with cElementTree on Python 2.5+") 33 | except ImportError: 34 | try: 35 | # Python 2.5 36 | import xml.etree.ElementTree as etree 37 | print("running with ElementTree on Python 2.5+") 38 | except ImportError: 39 | try: 40 | # normal cElementTree install 41 | import cElementTree as etree 42 | print("running with cElementTree") 43 | except ImportError: 44 | try: 45 | # normal ElementTree install 46 | import elementtree.ElementTree as etree 47 | print("running with ElementTree") 48 | except ImportError: 49 | print("Failed to import ElementTree from any known place") 50 | #----------------------------------------------------------------------------------- 51 | # ''' Readng a File ''' 52 | #----------------------------------------------------------------------------------- 53 | input_obj = open("vasprun.xml","r") 54 | input_doc = etree.parse(input_obj) 55 | root = input_doc.getroot() 56 | 57 | print("*"*80) 58 | print("dynmat") 59 | for type_tag in root.findall('*/dynmat/varray'): # search string in a Node 60 | value = type_tag.get('name') 61 | print(" |--> Child detected in a Node", value) 62 | print("*"*80) 63 | #----------------------------------------------------------------------------------- 64 | 65 | #*********************************Extracting Hessian******************************** 66 | # 67 | #We know the size of Hessian is always 3*N where N is the # of atoms in the unitcell 68 | # H = (3N,3N) 69 | #----------------------------------------------------------------------------------- 70 | 71 | hessian = root.xpath('*/dynmat/varray/v/text()') 72 | hess_v = [] 73 | 74 | for ind_hess in hessian: 75 | hess_v.append( ind_hess.split() ) 76 | hess_v = np.array(hess_v) 77 | 78 | print("*"*80) 79 | #print(hess_v) # for debugging ONLY 80 | row = len(hess_v); print("# of rows:", row) 81 | col = len(hess_v[0]); print("# of columns:", col) 82 | print("*"*80) 83 | #----------------------------------------------------------------------------------- 84 | 85 | #*********************** writing Hessian to a file ******************************** 86 | out = open('hessian.dat','w') 87 | 88 | for i in range( int(row/2) ): 89 | for j in range(col): 90 | #print(hess_v[i][j], end=' ' ) 91 | out.write( "{:18.11s}".format( hess_v[i][j]) ) 92 | out.write('\n') 93 | #print() 94 | 95 | out.close() 96 | 97 | #******************************End Hessian****************************************** 98 | 99 | 100 | #***************************extracting basevectors********************************** 101 | ''' 102 | lst_basevect = root.xpath('structure/crystal/varray/v/text()') 103 | xml_basevect = [] 104 | 105 | for ind_basevect in lst_basevect: 106 | xml_basevect.append( ind_basevect.split() ) 107 | print(np.array(xml_basevect)) 108 | 109 | #for i in range( (len(xml_basevect)) ): 110 | # print(i, xml_basevect[i][0], xml_basevect[i][1], xml_basevect[i][2]) 111 | 112 | #******************************End basevectors******************************** 113 | ''' 114 | #---------------------------------'''METHOD 2'''--------------------------------- 115 | 116 | a = [] ; l=0 117 | f = open('hessian.dat', 'r') 118 | 119 | for line in f.readlines(): 120 | a.append([]) 121 | #print (line[0]) 122 | if (line[0] == '#'): 123 | continue 124 | for i in line.strip().split(): 125 | a[-1].append(float(i)) 126 | l+=1 127 | #print (a) 128 | 129 | f.close() 130 | #------------------------------------------------------------------------ 131 | #a = np.random.random((900, 900)) 132 | s = np.shape(a); print('size of a Matrix', s) 133 | a = np.matrix(a) 134 | #print(a) 135 | print ('--------------------------------EIGVAL AND EIGVECTORS ARE:') 136 | 137 | eig, eig_v = LA.eigh(a) 138 | 139 | print (eig); 140 | print ( np.transpose(eig_v) ) 141 | -------------------------------------------------------------------------------- /Parsing-Hessian-matrix-from-vasprun/README.md: -------------------------------------------------------------------------------- 1 | # Parsing Hessian matrix from a file 2 | *Script to parse Hessian Matrix from a file* 3 | 4 | 5 | USAGE : To parse VASP vasprun.xml input file to extract Hessian Matrix 6 | Output file has already been defined in the code (hessian.dat). 7 | 8 | CAUTION: Use at your own risk (NOTEVEN IMPLIED GUARANTEED, WHATSOEVER), 9 | the code has been tested but the user in the end will have to verify the ouput. 10 | 11 | Xpath is useful tool for directly accessing the element in a Node 12 | 13 | -> CHECK this website for lxml introduccion: https://lxml.de/tutorial.html & 14 | -> https://github.com/lxml/lxml 15 | 16 | 17 | NB: The Matrix is obtained from VASP, vasprun.xml file. It contians the hessian matrix that can be edited with appropriate script. 18 | 19 | The complication that arises by parsing the data from the file is the trailing empty lines and tabs that need to be deleted before it can be read. In the case of a simple file format, there is no need for it. But if the file contains irregular data entry such as empty lines with commas and spaces then it needs to be formatted. 20 | 21 | In my case, I have only leading empty lines and spaces and in between columns there are white spaces of different sizes. 22 | 23 | 24 | AUTHOR : ASIF IQBAL BHATTI 25 | CREATED ON : 09/02/2020 26 | -------------------------------------------------------------------------------- /Parsing-Hessian-matrix-from-vasprun/parsing hessian matrix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import numpy as np 4 | import os, sys, subprocess 5 | from scipy import linalg as LA 6 | import matplotlib.pyplot as plt 7 | 8 | ''' The complication that arises by parsing the data from the file is the trailing empty lines and tabs that need to be deleted before it can be read. In the case of a simple file format, there is no need for it. But if the file contains irregular data entry such as empty lines with commas and spaces then it needs to be formatted. 9 | In my case, I have only leading empty lines and spaces and in between columns there are white spaces of different sizes. 10 | ''' 11 | 12 | filename = sys.argv[1] 13 | ######################################################################### 14 | #os.system(' grep "\S" input.txt') 15 | #os.system(" sed -e '/^\s*$/d' input.txt ") 16 | #os.system(" sed -i '/^[[:space:]]*$/d' $filename ") 17 | subprocess.call(['sed','-i','/^[[:space:]]*$/d',sys.argv[1]], shell = False) 18 | ######################################################################### 19 | 20 | #---------------------------------'''METHOD 1''' 21 | 22 | #a = np.loadtxt("new.dat") 23 | #print(a) 24 | 25 | #---------------------------------'''METHOD 2''' 26 | 27 | a = [] 28 | f = open(filename, 'r') 29 | 30 | for line in f.readlines(): 31 | a.append([]) 32 | for i in line.strip().split(): 33 | a[-1].append(float(i)) 34 | #print (a) 35 | 36 | f.close() 37 | #------------------------------------------------------------------------ 38 | #a = np.random.random((900, 900)) 39 | s = np.shape(a); print('size of a Matrix', s) 40 | a = np.matrix(a) 41 | #print(a) 42 | 43 | print ('--------------------------------EIG VAL AND EIG VECTORS ARE:') 44 | 45 | w, v = LA.eigh(a) 46 | 47 | print (w); 48 | print (v) 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Code to extract Elastic properties, Energy, and lattice parameter from VASP output files 2 | 3 | [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity) 4 | ![pypi](https://img.shields.io/pypi/v/pybadges.svg) 5 | ![versions](https://img.shields.io/pypi/pyversions/pybadges.svg) 6 | [![GPLv3 license](https://img.shields.io/badge/License-GPLv3-blue.svg)](http://perso.crans.org/besson/LICENSE.html) 7 | 8 | ==> supercell.py script constructs a bcc/fcc supercell for high-entropy alloys. 9 | 10 | This repository contains a set of Python scripts for analyzing High Entropy Alloys using VASP output files. The scripts can extract lattice parameters, energy, and volume from each directory in a given parent directory. Additionally, it can scan the CONTCAR file, compute the volume and lattice parameters, and print the volume difference upon structure minimization. The extracted data can be used to analyze the Elastic Constants and make decisions on adjusting ENCUT or KPOINTS to minimize Pulay stress, as indicated in the VASP manual. 11 | 12 | ``` 13 | **USAGE** : Just run the Main_file.py it will call all the modules 14 | The code has been given in one script (**Extract_elastic_energy_VASP.py**) and in modules. 15 | The module form is much easier to handle than one long complex code. 16 | ~/dir/ --> 17 | dir1 18 | dir2 19 | dir3 20 | POSCAR 21 | OUTCAR 22 | Python Main_file.py 23 | ``` 24 | _______________________ 25 | ## Structural Minimization in VASP: 26 | For VASP structural minimization, the following tags should be used: IBRION = 2; ISIF = 3; EDIFF = 10**-8. VASP implements both the stress method (First derivative approach) and the Energy-strain method for Elastic Constants calculation. The Energy-strain method involves applying Lagrangian strains to the cell and calculating the resulting energy for various deformations. Polynomial fitting is then performed, and the second derivative is calculated at equilibrium volume. 27 | 28 | ``` 29 | An exercise to print Cij matrix in a Pythonic way: 2D array is created as a List of Lists unlike C++ where you define by C[i][j] 30 | 31 | def print_Cij_Matrix(): 32 | Bij = [] 33 | C = "C" 34 | for i in range(0,6): 35 | Bij.append([]) 36 | for j in range(0,6): 37 | Bij[i].append((C + str(i) + str(j))) 38 | l = np.matrix(Bij) 39 | print (l) 40 | ``` 41 | 42 | ref: [exciting](http://exciting-code.org/nitrogen-energy-vs-strain-calculations) 43 | ref: [materialsproject](https://wiki.materialsproject.org/Elasticity_calculations) 44 | 45 | [![licensebuttons by-nd](https://licensebuttons.net/l/by-nd/3.0/88x31.png)](https://creativecommons.org/licenses/by-nd/4.0) 46 | 47 | **Parsing Hessian matrix from a file** 48 | 49 | Script to parse Hessian Matrix from a file 50 | 51 | USAGE: To parse the VASP vasprun.xml input file to extract the Hessian Matrix Output file has already been defined in the code (hessian.dat). 52 | 53 | CAUTION: Use at your own risk (NOTEVEN IMPLIED GUARANTEED, WHATSOEVER), the code has been tested but the user in the end will have to verify the ouput. 54 | 55 | Xpath is a useful tool for directly accessing the element in a Node 56 | 57 | -> CHECK this website for lxml introduccion: https://lxml.de/tutorial.html & -> https://github.com/lxml/lxml 58 | 59 | NB: The Matrix is obtained from VASP, vasprun.xml file. It contains the hessian matrix that can be edited with the appropriate script. 60 | 61 | The complication that arises by parsing the data from the file is the trailing empty lines and tabs that need to be deleted before it can be read. In the case of a simple file format, there is no need for it. But if the file contains irregular data entry such as empty lines with commas and spaces then it needs to be formatted. 62 | 63 | In my case, I have only leading empty lines and spaces and in between columns there are white spaces of different sizes. 64 | 65 | **Convert exciting(LMTO) input file to VASP input file (DFT code)** 66 | 67 | 68 | 𝗢𝗻𝗲 𝗳𝗶𝗲𝗹𝗱 𝗼𝗳 𝘄𝗼𝗿𝗸 𝗶𝗻 𝘄𝗵𝗶𝗰𝗵 𝘁𝗵𝗲𝗿𝗲 𝗵𝗮𝘀 𝗯𝗲𝗲𝗻 𝘁𝗼𝗼 𝗺𝘂𝗰𝗵 𝘀𝗽𝗲𝗰𝘂𝗹𝗮𝘁𝗶𝗼𝗻 𝗶𝘀 𝗰𝗼𝘀𝗺𝗼𝗹𝗼𝗴𝘆. 𝗧𝗵𝗲𝗿𝗲 𝗮𝗿𝗲 𝘃𝗲𝗿𝘆 𝗳𝗲𝘄 𝗵𝗮𝗿𝗱 𝗳𝗮𝗰𝘁𝘀 𝘁𝗼 𝗴𝗼 𝗼𝗻, 𝗯𝘂𝘁 𝘁𝗵𝗲𝗼𝗿𝗲𝘁𝗶𝗰𝗮𝗹 𝘄𝗼𝗿𝗸𝗲𝗿𝘀 𝗵𝗮𝘃𝗲 𝗯𝗲𝗲𝗻 𝗯𝘂𝘀𝘆 𝗰𝗼𝗻𝘀𝘁𝗿𝘂𝗰𝘁𝗶𝗻𝗴 𝘃𝗮𝗿𝗶𝗼𝘂𝘀 𝗺𝗼𝗱𝗲𝗹𝘀 𝗳𝗼𝗿 𝘁𝗵𝗲 𝗨𝗻𝗶𝘃𝗲𝗿𝘀𝗲, 𝗯𝗮𝘀𝗲𝗱 𝗼𝗻 𝗮𝗻𝘆 𝗮𝘀𝘀𝘂𝗺𝗽𝘁𝗶𝗼𝗻𝘀 𝘁𝗵𝗮𝘁 𝘁𝗵𝗲𝘆 𝗳𝗮𝗻𝗰𝘆. 𝗧𝗵𝗲𝘀𝗲 𝗺𝗼𝗱𝗲𝗹𝘀 𝗮𝗿𝗲 𝗽𝗿𝗼𝗯𝗮𝗯𝗹𝘆 𝗮𝗹𝗹 𝘄𝗿𝗼𝗻𝗴. 𝗜𝘁 𝗶𝘀 𝘂𝘀𝘂𝗮𝗹𝗹𝘆 𝗮𝘀𝘀𝘂𝗺𝗲𝗱 𝘁𝗵𝗮𝘁 𝘁𝗵𝗲 𝗹𝗮𝘄𝘀 𝗼𝗳 𝗻𝗮𝘁𝘂𝗿𝗲 𝗵𝗮𝘃𝗲 𝗮𝗹𝘄𝗮𝘆𝘀 𝗯𝗲𝗲𝗻 𝘁𝗵𝗲 𝘀𝗮𝗺𝗲 𝗮𝘀 𝘁𝗵𝗲𝘆 𝗮𝗿𝗲 𝗻𝗼𝘄. 𝗧𝗵𝗲𝗿𝗲 𝗶𝘀 𝗻𝗼 𝗷𝘂𝘀𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗳𝗼𝗿 𝘁𝗵𝗶𝘀. 𝗧𝗵𝗲 𝗹𝗮𝘄𝘀 𝗺𝗮𝘆 𝗯𝗲 𝗰𝗵𝗮𝗻𝗴𝗶𝗻𝗴, 𝗮𝗻𝗱 𝗶𝗻 𝗽𝗮𝗿𝘁𝗶𝗰𝘂𝗹𝗮𝗿, 𝗾𝘂𝗮𝗻𝘁𝗶𝘁𝗶𝗲𝘀 𝘁𝗵𝗮𝘁 𝗮𝗿𝗲 𝗰𝗼𝗻𝘀𝗶𝗱𝗲𝗿𝗲𝗱 𝘁𝗼 𝗯𝗲 𝗰𝗼𝗻𝘀𝘁𝗮𝗻𝘁𝘀 𝗼𝗳 𝗻𝗮𝘁𝘂𝗿𝗲 𝗺𝗮𝘆 𝗯𝗲 𝘃𝗮𝗿𝘆𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 𝗰𝗼𝘀𝗺𝗼𝗹𝗼𝗴𝗶𝗰𝗮𝗹 𝘁𝗶𝗺𝗲. 𝗦𝘂𝗰𝗵 𝘃𝗮𝗿𝗶𝗮𝘁𝗶𝗼𝗻𝘀 𝘄𝗼𝘂𝗹𝗱 𝗰𝗼𝗺𝗽𝗹𝗲𝘁𝗲𝗹𝘆 𝘂𝗽𝘀𝗲𝘁 𝘁𝗵𝗲 𝗺𝗼𝗱𝗲𝗹 𝗺𝗮𝗸𝗲𝗿𝘀." 𝗗𝗶𝗿𝗮𝗰, 𝗣𝗮𝘂𝗹. 𝗢𝗻 𝗺𝗲𝘁𝗵𝗼𝗱𝘀 𝗶𝗻 𝘁𝗵𝗲𝗼𝗿𝗲𝘁𝗶𝗰𝗮𝗹 𝗽𝗵𝘆𝘀𝗶𝗰𝘀. (𝗧𝗿𝗶𝗲𝘀𝘁𝗲. 𝗝𝘂𝗻𝗲 𝟭𝟵𝟲𝟴 .) 69 | 70 | -------------------------------------------------------------------------------- /Thermal_properties_from_phonopy/extract_thermal_yaml.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import yaml 4 | 5 | with open("thermal_properties.yaml") as f: 6 | data = yaml.load(f, Loader=yaml.FullLoader) 7 | 8 | 9 | # isinstance checks whether the value is a list and if list 10 | # we count the number of elements it contains. 11 | # dict = {key, value} pair 12 | 13 | count = sum(len(data[x]) for x in data if isinstance(data[x], list)) 14 | print(f"# of elements detected in the list: {count}") 15 | 16 | 17 | print ("{:1s} {:14.12s} {:14.12s} {}".format(' ','Temperature', 'Entropy', 'Free_energy') ) 18 | for i in range(count): 19 | temperature=data['thermal_properties'][i]['temperature'] 20 | free_energy=data['thermal_properties'][i]['free_energy'] 21 | entropy=data['thermal_properties'][i]['entropy'] 22 | heat_capacity=data['thermal_properties'][i]['heat_capacity'] 23 | energy=data['thermal_properties'][i]['energy'] 24 | print ("{:10.3f} {:15.8f} {:15.8f}".format(temperature, entropy, free_energy) ) -------------------------------------------------------------------------------- /Thermal_properties_from_phonopy/thermal_properties.yaml: -------------------------------------------------------------------------------- 1 | # Thermal properties / unit cell (natom) 2 | 3 | unit: 4 | temperature: K 5 | free_energy: kJ/mol 6 | entropy: J/K/mol 7 | heat_capacity: J/K/mol 8 | 9 | natom: 20 10 | cutoff_frequency: 0.000 11 | num_modes: 60000 12 | num_integrated_modes: 59704 13 | 14 | zero_point_energy: 42.9872098 15 | high_T_entropy: 2141.4755667 16 | 17 | thermal_properties: 18 | - temperature: 0.0000000 19 | free_energy: 42.9872098 20 | entropy: 0.0000000 21 | heat_capacity: 0.0000000 22 | energy: 42.9872098 23 | 24 | - temperature: 10.0000000 25 | free_energy: 42.9701598 26 | entropy: 5.0621935 27 | heat_capacity: 10.0394672 28 | energy: 43.0207817 29 | 30 | - temperature: 20.0000000 31 | free_energy: 42.8486108 32 | entropy: 21.4264301 33 | heat_capacity: 45.8642680 34 | energy: 43.2771394 35 | 36 | - temperature: 30.0000000 37 | free_energy: 42.4997264 38 | entropy: 50.1853341 39 | heat_capacity: 101.7453167 40 | energy: 44.0052864 41 | 42 | - temperature: 40.0000000 43 | free_energy: 41.8153259 44 | entropy: 87.8154694 45 | heat_capacity: 162.6125091 46 | energy: 45.3279447 47 | 48 | - temperature: 50.0000000 49 | free_energy: 40.7274267 50 | entropy: 130.2807415 51 | heat_capacity: 218.8599497 52 | energy: 47.2414637 53 | 54 | - temperature: 60.0000000 55 | free_energy: 39.2038334 56 | entropy: 174.5477101 57 | heat_capacity: 266.6851313 58 | energy: 49.6766960 59 | 60 | - temperature: 70.0000000 61 | free_energy: 37.2369562 62 | entropy: 218.6973499 63 | heat_capacity: 305.7350219 64 | energy: 52.5457707 65 | 66 | - temperature: 80.0000000 67 | free_energy: 34.8339454 68 | entropy: 261.6468591 69 | heat_capacity: 337.0831464 70 | energy: 55.7656941 71 | 72 | - temperature: 90.0000000 73 | free_energy: 32.0098700 74 | entropy: 302.8514103 75 | heat_capacity: 362.1458102 76 | energy: 59.2664969 77 | 78 | - temperature: 100.0000000 79 | free_energy: 28.7835039 80 | entropy: 342.0857215 81 | heat_capacity: 382.2401526 82 | energy: 62.9920761 83 | 84 | - temperature: 110.0000000 85 | free_energy: 25.1748838 86 | entropy: 379.3046380 87 | heat_capacity: 398.4548176 88 | energy: 66.8983940 89 | 90 | - temperature: 120.0000000 91 | free_energy: 21.2039627 92 | entropy: 414.5596025 93 | heat_capacity: 411.6456883 94 | energy: 70.9511150 95 | 96 | - temperature: 130.0000000 97 | free_energy: 16.8899083 98 | entropy: 447.9502538 99 | heat_capacity: 422.4714642 100 | energy: 75.1234413 101 | 102 | - temperature: 140.0000000 103 | free_energy: 12.2507712 104 | entropy: 479.5970017 105 | heat_capacity: 431.4354531 106 | energy: 79.3943515 107 | 108 | - temperature: 150.0000000 109 | free_energy: 7.3033610 110 | entropy: 509.6258367 111 | heat_capacity: 438.9223243 112 | energy: 83.7472365 113 | 114 | - temperature: 160.0000000 115 | free_energy: 2.0632353 116 | entropy: 538.1601906 117 | heat_capacity: 445.2273388 118 | energy: 88.1688658 119 | 120 | - temperature: 170.0000000 121 | free_energy: -3.4552514 122 | entropy: 565.3168297 123 | heat_capacity: 450.5786019 124 | energy: 92.6486097 125 | 126 | - temperature: 180.0000000 127 | free_energy: -9.2388708 128 | entropy: 591.2040311 129 | heat_capacity: 455.1536804 130 | energy: 97.1778548 131 | 132 | - temperature: 190.0000000 133 | free_energy: -15.2754323 134 | entropy: 615.9210317 135 | heat_capacity: 459.0919218 136 | energy: 101.7495637 137 | 138 | - temperature: 200.0000000 139 | free_energy: -21.5536929 140 | entropy: 639.5581662 141 | heat_capacity: 462.5035816 142 | energy: 106.3579404 143 | 144 | - temperature: 210.0000000 145 | free_energy: -28.0632701 146 | entropy: 662.1973578 147 | heat_capacity: 465.4766070 148 | energy: 110.9981751 149 | 150 | - temperature: 220.0000000 151 | free_energy: -34.7945615 152 | entropy: 683.9127687 153 | heat_capacity: 468.0817060 154 | energy: 115.6662476 155 | 156 | - temperature: 230.0000000 157 | free_energy: -41.7386705 158 | entropy: 704.7715019 159 | heat_capacity: 470.3761596 160 | energy: 120.3587749 161 | 162 | - temperature: 240.0000000 163 | free_energy: -48.8873391 164 | entropy: 724.8342962 165 | heat_capacity: 472.4067087 166 | energy: 125.0728920 167 | 168 | - temperature: 250.0000000 169 | free_energy: -56.2328873 170 | entropy: 744.1561819 171 | heat_capacity: 474.2117581 172 | energy: 129.8061581 173 | 174 | - temperature: 260.0000000 175 | free_energy: -63.7681599 176 | entropy: 762.7870843 177 | heat_capacity: 475.8230705 178 | energy: 134.5564820 179 | 180 | - temperature: 270.0000000 181 | free_energy: -71.4864774 182 | entropy: 780.7723695 183 | heat_capacity: 477.2670794 184 | energy: 139.3220623 185 | 186 | - temperature: 280.0000000 187 | free_energy: -79.3815933 188 | entropy: 798.1533334 189 | heat_capacity: 478.5659125 190 | energy: 144.1013400 191 | 192 | - temperature: 290.0000000 193 | free_energy: -87.4476556 194 | entropy: 814.9676367 195 | heat_capacity: 479.7381969 196 | energy: 148.8929591 197 | 198 | - temperature: 300.0000000 199 | free_energy: -95.6791722 200 | entropy: 831.2496905 201 | heat_capacity: 480.7996959 202 | energy: 153.6957349 203 | 204 | - temperature: 310.0000000 205 | free_energy: -104.0709805 206 | entropy: 847.0309972 207 | heat_capacity: 481.7638159 208 | energy: 158.5086286 209 | 210 | - temperature: 320.0000000 211 | free_energy: -112.6182196 212 | entropy: 862.3404519 213 | heat_capacity: 482.6420132 214 | energy: 163.3307250 215 | 216 | - temperature: 330.0000000 217 | free_energy: -121.3163055 218 | entropy: 877.2046087 219 | heat_capacity: 483.4441216 220 | energy: 168.1612154 221 | 222 | - temperature: 340.0000000 223 | free_energy: -130.1609091 224 | entropy: 891.6479157 225 | heat_capacity: 484.1786182 226 | energy: 172.9993822 227 | 228 | - temperature: 350.0000000 229 | free_energy: -139.1479363 230 | entropy: 905.6929236 231 | heat_capacity: 484.8528402 232 | energy: 177.8445869 233 | 234 | - temperature: 360.0000000 235 | free_energy: -148.2735096 236 | entropy: 919.3604695 237 | heat_capacity: 485.4731629 238 | energy: 182.6962594 239 | 240 | - temperature: 370.0000000 241 | free_energy: -157.5339519 242 | entropy: 932.6698408 243 | heat_capacity: 486.0451459 244 | energy: 187.5538892 245 | 246 | - temperature: 380.0000000 247 | free_energy: -166.9257722 248 | entropy: 945.6389204 249 | heat_capacity: 486.5736544 250 | energy: 192.4170175 251 | 252 | - temperature: 390.0000000 253 | free_energy: -176.4456515 254 | entropy: 958.2843158 255 | heat_capacity: 487.0629602 256 | energy: 197.2852316 257 | 258 | - temperature: 400.0000000 259 | free_energy: -186.0904312 260 | entropy: 970.6214746 261 | heat_capacity: 487.5168259 262 | energy: 202.1581586 263 | 264 | - temperature: 410.0000000 265 | free_energy: -195.8571016 266 | entropy: 982.6647872 267 | heat_capacity: 487.9385758 268 | energy: 207.0354611 269 | 270 | - temperature: 420.0000000 271 | free_energy: -205.7427923 272 | entropy: 994.4276792 273 | heat_capacity: 488.3311550 274 | energy: 211.9168330 275 | 276 | - temperature: 430.0000000 277 | free_energy: -215.7447624 278 | entropy: 1005.9226933 279 | heat_capacity: 488.6971806 280 | energy: 216.8019957 281 | 282 | - temperature: 440.0000000 283 | free_energy: -225.8603924 284 | entropy: 1017.1615643 285 | heat_capacity: 489.0389837 286 | energy: 221.6906959 287 | 288 | - temperature: 450.0000000 289 | free_energy: -236.0871766 290 | entropy: 1028.1552850 291 | heat_capacity: 489.3586463 292 | energy: 226.5827016 293 | 294 | - temperature: 460.0000000 295 | free_energy: -246.4227154 296 | entropy: 1038.9141666 297 | heat_capacity: 489.6580324 298 | energy: 231.4778012 299 | 300 | - temperature: 470.0000000 301 | free_energy: -256.8647095 302 | entropy: 1049.4478931 303 | heat_capacity: 489.9388147 304 | energy: 236.3758003 305 | 306 | - temperature: 480.0000000 307 | free_energy: -267.4109532 308 | entropy: 1059.7655702 309 | heat_capacity: 490.2024974 310 | energy: 241.2765205 311 | 312 | - temperature: 490.0000000 313 | free_energy: -278.0593293 314 | entropy: 1069.8757696 315 | heat_capacity: 490.4504363 316 | energy: 246.1797978 317 | 318 | - temperature: 500.0000000 319 | free_energy: -288.8078039 320 | entropy: 1079.7865696 321 | heat_capacity: 490.6838561 322 | energy: 251.0854809 323 | 324 | - temperature: 510.0000000 325 | free_energy: -299.6544215 326 | entropy: 1089.5055916 327 | heat_capacity: 490.9038648 328 | energy: 255.9934302 329 | 330 | - temperature: 520.0000000 331 | free_energy: -310.5973006 332 | entropy: 1099.0400334 333 | heat_capacity: 491.1114673 334 | energy: 260.9035168 335 | 336 | - temperature: 530.0000000 337 | free_energy: -321.6346296 338 | entropy: 1108.3966998 339 | heat_capacity: 491.3075762 340 | energy: 265.8156213 341 | 342 | - temperature: 540.0000000 343 | free_energy: -332.7646635 344 | entropy: 1117.5820301 345 | heat_capacity: 491.4930220 346 | energy: 270.7296328 347 | 348 | - temperature: 550.0000000 349 | free_energy: -343.9857195 350 | entropy: 1126.6021239 351 | heat_capacity: 491.6685618 352 | energy: 275.6454487 353 | 354 | - temperature: 560.0000000 355 | free_energy: -355.2961745 356 | entropy: 1135.4627639 357 | heat_capacity: 491.8348869 358 | energy: 280.5629733 359 | 360 | - temperature: 570.0000000 361 | free_energy: -366.6944616 362 | entropy: 1144.1694375 363 | heat_capacity: 491.9926294 364 | energy: 285.4821178 365 | 366 | - temperature: 580.0000000 367 | free_energy: -378.1790674 368 | entropy: 1152.7273563 369 | heat_capacity: 492.1423682 370 | energy: 290.4027992 371 | 372 | - temperature: 590.0000000 373 | free_energy: -389.7485294 374 | entropy: 1161.1414740 375 | heat_capacity: 492.2846346 376 | energy: 295.3249403 377 | 378 | - temperature: 600.0000000 379 | free_energy: -401.4014333 380 | entropy: 1169.4165032 381 | heat_capacity: 492.4199162 382 | energy: 300.2484687 383 | 384 | - temperature: 610.0000000 385 | free_energy: -413.1364108 386 | entropy: 1177.5569305 387 | heat_capacity: 492.5486621 388 | energy: 305.1733168 389 | 390 | - temperature: 620.0000000 391 | free_energy: -424.9521375 392 | entropy: 1185.5670306 393 | heat_capacity: 492.6712854 394 | energy: 310.0994215 395 | 396 | - temperature: 630.0000000 397 | free_energy: -436.8473306 398 | entropy: 1193.4508793 399 | heat_capacity: 492.7881676 400 | energy: 315.0267234 401 | 402 | - temperature: 640.0000000 403 | free_energy: -448.8207472 404 | entropy: 1201.2123658 405 | heat_capacity: 492.8996607 406 | energy: 319.9551669 407 | 408 | - temperature: 650.0000000 409 | free_energy: -460.8711824 410 | entropy: 1208.8552033 411 | heat_capacity: 493.0060904 412 | energy: 324.8846997 413 | 414 | - temperature: 660.0000000 415 | free_energy: -472.9974676 416 | entropy: 1216.3829401 417 | heat_capacity: 493.1077581 418 | energy: 329.8152728 419 | 420 | - temperature: 670.0000000 421 | free_energy: -485.1984689 422 | entropy: 1223.7989684 423 | heat_capacity: 493.2049431 424 | energy: 334.7468400 425 | 426 | - temperature: 680.0000000 427 | free_energy: -497.4730855 428 | entropy: 1231.1065339 429 | heat_capacity: 493.2979047 430 | energy: 339.6793576 431 | 432 | - temperature: 690.0000000 433 | free_energy: -509.8202484 434 | entropy: 1238.3087437 435 | heat_capacity: 493.3868836 436 | energy: 344.6127848 437 | 438 | - temperature: 700.0000000 439 | free_energy: -522.2389191 440 | entropy: 1245.4085741 441 | heat_capacity: 493.4721038 442 | energy: 349.5470828 443 | 444 | - temperature: 710.0000000 445 | free_energy: -534.7280881 446 | entropy: 1252.4088777 447 | heat_capacity: 493.5537735 448 | energy: 354.4822150 449 | 450 | - temperature: 720.0000000 451 | free_energy: -547.2867740 452 | entropy: 1259.3123904 453 | heat_capacity: 493.6320871 454 | energy: 359.4181470 455 | 456 | - temperature: 730.0000000 457 | free_energy: -559.9140221 458 | entropy: 1266.1217373 459 | heat_capacity: 493.7072257 460 | energy: 364.3548462 461 | 462 | - temperature: 740.0000000 463 | free_energy: -572.6089033 464 | entropy: 1272.8394390 465 | heat_capacity: 493.7793582 466 | energy: 369.2922815 467 | 468 | - temperature: 750.0000000 469 | free_energy: -585.3705134 470 | entropy: 1279.4679164 471 | heat_capacity: 493.8486427 472 | energy: 374.2304238 473 | 474 | - temperature: 760.0000000 475 | free_energy: -598.1979720 476 | entropy: 1286.0094965 477 | heat_capacity: 493.9152270 478 | energy: 379.1692454 479 | 480 | - temperature: 770.0000000 481 | free_energy: -611.0904212 482 | entropy: 1292.4664169 483 | heat_capacity: 493.9792493 484 | energy: 384.1087199 485 | 486 | - temperature: 780.0000000 487 | free_energy: -624.0470253 488 | entropy: 1298.8408302 489 | heat_capacity: 494.0408393 490 | energy: 389.0488223 491 | 492 | - temperature: 790.0000000 493 | free_energy: -637.0669697 494 | entropy: 1305.1348084 495 | heat_capacity: 494.1001184 496 | energy: 393.9895289 497 | 498 | - temperature: 800.0000000 499 | free_energy: -650.1494600 500 | entropy: 1311.3503467 501 | heat_capacity: 494.1572006 502 | energy: 398.9308173 503 | 504 | - temperature: 810.0000000 505 | free_energy: -663.2937216 506 | entropy: 1317.4893673 507 | heat_capacity: 494.2121931 508 | energy: 403.8726660 509 | 510 | - temperature: 820.0000000 511 | free_energy: -676.4989985 512 | entropy: 1323.5537232 513 | heat_capacity: 494.2651965 514 | energy: 408.8150545 515 | 516 | - temperature: 830.0000000 517 | free_energy: -689.7645531 518 | entropy: 1329.5452008 519 | heat_capacity: 494.3163054 520 | energy: 413.7579636 521 | 522 | - temperature: 840.0000000 523 | free_energy: -703.0896653 524 | entropy: 1335.4655238 525 | heat_capacity: 494.3656090 526 | energy: 418.7013746 527 | 528 | - temperature: 850.0000000 529 | free_energy: -716.4736320 530 | entropy: 1341.3163553 531 | heat_capacity: 494.4131912 532 | energy: 423.6452700 533 | 534 | - temperature: 860.0000000 535 | free_energy: -729.9157662 536 | entropy: 1347.0993013 537 | heat_capacity: 494.4591311 538 | energy: 428.5896330 539 | 540 | - temperature: 870.0000000 541 | free_energy: -743.4153969 542 | entropy: 1352.8159130 543 | heat_capacity: 494.5035033 544 | energy: 433.5344474 545 | 546 | - temperature: 880.0000000 547 | free_energy: -756.9718683 548 | entropy: 1358.4676890 549 | heat_capacity: 494.5463784 550 | energy: 438.4796981 551 | 552 | - temperature: 890.0000000 553 | free_energy: -770.5845394 554 | entropy: 1364.0560782 555 | heat_capacity: 494.5878227 556 | energy: 443.4253702 557 | 558 | - temperature: 900.0000000 559 | free_energy: -784.2527832 560 | entropy: 1369.5824813 561 | heat_capacity: 494.6278993 562 | energy: 448.3714500 563 | 564 | - temperature: 910.0000000 565 | free_energy: -797.9759869 566 | entropy: 1375.0482536 567 | heat_capacity: 494.6666675 568 | energy: 453.3179239 569 | 570 | - temperature: 920.0000000 571 | free_energy: -811.7535506 572 | entropy: 1380.4547062 573 | heat_capacity: 494.7041837 574 | energy: 458.2647791 575 | 576 | - temperature: 930.0000000 577 | free_energy: -825.5848875 578 | entropy: 1385.8031087 579 | heat_capacity: 494.7405011 580 | energy: 463.2120035 581 | 582 | - temperature: 940.0000000 583 | free_energy: -839.4694234 584 | entropy: 1391.0946901 585 | heat_capacity: 494.7756703 586 | energy: 468.1595853 587 | 588 | - temperature: 950.0000000 589 | free_energy: -853.4065959 590 | entropy: 1396.3306412 591 | heat_capacity: 494.8097390 592 | energy: 473.1075133 593 | 594 | - temperature: 960.0000000 595 | free_energy: -867.3958546 596 | entropy: 1401.5121158 597 | heat_capacity: 494.8427527 598 | energy: 478.0557766 599 | 600 | - temperature: 970.0000000 601 | free_energy: -881.4366604 602 | entropy: 1406.6402323 603 | heat_capacity: 494.8747545 604 | energy: 483.0043650 605 | 606 | - temperature: 980.0000000 607 | free_energy: -895.5284850 608 | entropy: 1411.7160750 609 | heat_capacity: 494.9057851 610 | energy: 487.9532684 611 | 612 | - temperature: 990.0000000 613 | free_energy: -909.6708111 614 | entropy: 1416.7406956 615 | heat_capacity: 494.9358836 616 | energy: 492.9024776 617 | 618 | - temperature: 1000.0000000 619 | free_energy: -923.8631316 620 | entropy: 1421.7151147 621 | heat_capacity: 494.9650869 622 | energy: 497.8519831 623 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-midnight -------------------------------------------------------------------------------- /convert_ExcitingXml2Vasp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from lxml import etree 4 | import xml.etree.ElementTree as xml 5 | from math import * 6 | import sys, getopt, os 7 | from sys import stdout 8 | from array import * 9 | import numpy as np 10 | 11 | from termcolor import colored 12 | 13 | #*******************************DOCUMENTATION*********************************** 14 | # 15 | #AUTHOR : ASIF IQBAL BHATTI 16 | #CREATED ON : 29/04/2020 17 | #USAGE : To parse an EXCITING xml input file to VASP format. 18 | #Output file has already been defined in the code (POSCAR.vasp). 19 | #CAUTION: Use at your own risk (NOTEVEN IMPLIED GUARANTEED, WHATSOEVER), 20 | #the code has been tested but the user in the end will have to verify the ouput 21 | #geometry and be vary of the order of atoms in list. 22 | # 23 | #************************END OF DOCUMENTATION*********************************** 24 | 25 | Bohr2angstrom = 0.529177249 26 | yellow = '\033[01;33m' 27 | red = '\033[01;31m' 28 | blue = '\x1b[01;34m' 29 | cyan = '\x1b[01;36m' 30 | green = yellow 31 | 32 | #*********************DEFINITION FOR INPUTFILE********************************** 33 | 34 | if len(sys.argv) < 2: 35 | sys.exit(f'Usage: {sys.argv[0]} ') 36 | 37 | tree = xml.parse(sys.argv[1]) 38 | root = tree.getroot() 39 | 40 | struct = root.getchildren()[1] # pivot for controling element 41 | lattice = struct.getchildren() 42 | 43 | 44 | with open('POSCAR.vasp', 'w+') as f: 45 | print (colored("\nExtracting information from input file... ", 'yellow')) 46 | print ('-'*80) 47 | print (colored(" | Title is: ", 'yellow'), root.findtext('title')) 48 | f.write(root.findtext('title')) 49 | 50 | #*************************DETECTING # OF SPECIES****************************** 51 | 52 | i = 0 53 | for _ in struct: 54 | i = i+1 55 | print (colored(" | Species detected: ", 'yellow'), i-1 ) 56 | f.write(" |\t Number of species detected: {:d}\n".format(i-1)) 57 | 58 | #***************************SCALING DEFINITION******************************** 59 | #reading from a file 60 | for sca in struct.findall('crystal'): 61 | for key in sca.attrib: 62 | sc = sca.get('scale') if key == 'scale' else 1.0 63 | print (colored(" | Scaling factor is: ", 'yellow'), float(sc)) 64 | print (colored(" | Converting bohr to angstrom ... ", 'yellow')) 65 | print (colored(" | Writing to a File in VASP format ... ", 'yellow')) 66 | f.write("%f\n" % 1.0) 67 | print ('-'*80) 68 | 69 | #***********************LATTICE VECTORS SECTION************************ 70 | #reading from a file 71 | lv = [] 72 | for vect in struct.findall('crystal'): 73 | #lat = vect.find('basevect') 74 | lv.extend(k.text.split() for k in vect.findall('basevect')) 75 | ### 76 | 77 | convertion = Bohr2angstrom*float(sc) 78 | for list in lv: 79 | print ("\t{:10.8f} {:10.8f} {:10.8f}".format(float(list[0])*convertion, 80 | float(list[1])*convertion, float(list[2])*convertion ) ) 81 | f.write ("\t{:10.8f} {:10.8f} {:10.8f}\n".format(float(list[0])*convertion, 82 | float(list[1])*convertion, float(list[2])*convertion ) ) 83 | 84 | #******************SPECIES CONTROL SECTION********************************* 85 | 86 | lab = [] 87 | for coord in struct.findall('species'): 88 | spe = coord.get('speciesfile') 89 | jj = os.path.splitext(spe) 90 | lab.append(jj[0]) 91 | 92 | sp = [] 93 | for x in range(i-1): 94 | print("{:s}".format(lab[x])) 95 | f.write("\t%s" % lab[x]) 96 | sp.extend(lab[x] for _ in struct[x+1].iter('atom')) 97 | f.write("\n") 98 | 99 | for h in range(i-1): 100 | print("\t{:d}".format(sp.count(lab[h])) ) 101 | f.write("\t%d" % sp.count(lab[h])) 102 | f.write("\n") 103 | 104 | #*******************CONTROL SECTION FOR CARTESIAN COORDINATE*************** 105 | 106 | lll = [] 107 | ccl = [] 108 | checker = False 109 | for cart in root.findall('structure'): 110 | ca = cart.get('cartesian') 111 | for key in cart.attrib: 112 | if key == 'cartesian': 113 | checker = True 114 | if ca == "true": 115 | print ("Cartesian") 116 | f.write("Cartesian\n") 117 | for i in range(i-1): 118 | for s in struct[i+1].iter('atom'): 119 | atom = s.get('coord') 120 | ccl.append(atom.split()) 121 | lll.append(lab[i]) 122 | # print (atom, lab[i]) 123 | 124 | for list in ccl: 125 | print ("{:5.8f} {:5.8f} {:5.8f}".format(float(list[0])* Bohr2angstrom, 126 | float(list[1])* Bohr2angstrom, float(list[2])* Bohr2angstrom ) ) 127 | f.write ("{:5.8f} {:5.8f} {:5.8f}\n".format(float(list[0])* Bohr2angstrom, 128 | float(list[1])* Bohr2angstrom, float(list[2])* Bohr2angstrom ) ) 129 | 130 | #**************************DIRECT COORDINATE********************* 131 | 132 | else: 133 | print ("Direct") 134 | f.write ("Direct\n") 135 | for i in range(i-1): 136 | for s in struct[i+1].iter('atom'): 137 | atom = s.get('coord') 138 | ccl.append(atom.split()) 139 | lll.append(lab[i]) 140 | # print (atom, lab[i]) 141 | # print (ccl) 142 | 143 | for list in ccl: 144 | print ("{:5.8f} {:5.8f} {:5.8f}".format(float(list[0]), 145 | float(list[1]), float(list[2]) ) ) 146 | f.write ("{:5.8f} {:5.8f} {:5.8f}\n".format(float(list[0]), 147 | float(list[1]), float(list[2]) ) ) 148 | 149 | print (colored("File generated ... ", 'green')) 150 | -------------------------------------------------------------------------------- /get_TotEle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | ''' 4 | #===================================================== 5 | # AUTHOR: Asif Iqbal 6 | # GitHUB: Asif_em 7 | # PURPOSE: Read CHGCAR file and compute the integrated 8 | # charge density to sum up to # of electrons. 9 | # Dependency on pymatgen module 10 | # The following code is uploaded to my GitHub 11 | # 12 | #===================================================== 13 | ''' 14 | 15 | import numpy as np 16 | import matplotlib.pyplot as plt 17 | from pymatgen.io.vasp.outputs import VolumetricData 18 | 19 | poscar, data, data_aug = VolumetricData.parse_file('CHGCAR') 20 | latt = np.array(poscar.structure.lattice.matrix) 21 | 22 | # As per VASP the CHGCAR needs to be divided by Volume 23 | # COuld be total or diff if ISPIN = 2 24 | chgd = data["total"] / np.linalg.det(latt) 25 | pos = poscar.structure.cart_coords 26 | # get volume per grid point 27 | dv = np.linalg.det(latt)/(np.array(chgd).shape[0]*np.array(chgd).shape[1]*np.array(chgd).shape[2]) 28 | # get the step size in each direction (x, y, z) 29 | dr = latt/np.array(chgd).shape 30 | total_elect = np.sum(np.array(chgd))*dv 31 | num_grid_points = np.prod(np.array(chgd).shape) 32 | integrated_charge = np.cumsum(np.array(chgd)) * dv 33 | # Measure the charge density sphere 34 | distance = np.linspace(0, np.linalg.norm(dr), num_grid_points) 35 | 36 | print(dv, np.linalg.norm(dr)) 37 | print(f"Shape of data in CHGCAR file:: {np.array(chgd).shape}") 38 | print(f"Total integrated electron number = {total_elect:8.5f}") 39 | # ploting 40 | plt.plot(distance, integrated_charge, '-o', color='m', linewidth=0.5, markersize=0.5, markerfacecolor='none') 41 | plt.xlabel("Distance from the freestanding O atom (Å)") 42 | plt.ylabel("Integrated charge") 43 | plt.savefig('dvsQ.png', dpi=400, bbox_inches='tight') 44 | plt.show() 45 | 46 | -------------------------------------------------------------------------------- /get_forces_all_ionicSteps.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | ''' 4 | # ***************************************************************************** 5 | # USAGE :: python3 grad2.py 6 | # AUTHOR:: ADAPTATION OF Peter Larsson script to new version @ASIFIQBAL 7 | # please see => https://www.nsc.liu.se/~pla/vasptools/ 8 | # ABOUT THE PROGRAM: 9 | # It prints out the forces at each ionic steps during simulation 10 | # ***************************************************************************** 11 | ''' 12 | 13 | import os, sys, re 14 | import numpy as np 15 | import subprocess 16 | 17 | def get_number_of_atoms(out_car): 18 | return int(subprocess.Popen('grep "NIONS" ' + out_car, stdout=subprocess.PIPE, shell=True).communicate()[0].split()[11]) 19 | #print( int(subprocess.Popen('grep "NIONS" ' + where, stdout=subprocess.PIPE, shell=True).communicate()[0].split()[11]) ) 20 | 21 | def get_ediff(out_car): 22 | return float(subprocess.Popen('grep " EDIFF" ' + out_car, stdout=subprocess.PIPE, shell=True).communicate()[0].split()[2]) 23 | #print( float(subprocess.Popen('grep " EDIFF" ' + where, stdout=subprocess.PIPE, shell=True).communicate()[0].split()[2]) ) 24 | 25 | OKGREEN = '\033[92m' 26 | WARNING = '\033[93m' 27 | FAIL = '\033[91m' 28 | ENDC = '\033[0m' 29 | 30 | # ***************************************** 31 | # Main program 32 | # ***************************************** 33 | try: 34 | outcar = open(sys.argv[1],"r") 35 | except IOError: 36 | sys.stderr.write(FAIL) 37 | sys.stderr.write("No OUTCAR file") 38 | sys.stderr.write(ENDC+"\n") 39 | sys.exit(1) 40 | 41 | if outcar != None: 42 | outcarfile = sys.argv[1] 43 | outcarlines = outcar.readlines() 44 | 45 | #Find max iterations 46 | nelmax = int( 47 | subprocess.Popen( 48 | 'grep "NELM " ' + outcarfile, stdout=subprocess.PIPE, 49 | shell=True).communicate()[0].split()[2][:-1]) 50 | natoms = get_number_of_atoms(outcarfile) 51 | ediff = np.log10(float(get_ediff(outcarfile))) 52 | 53 | re_energy = re.compile("free energy") 54 | re_iteration = re.compile("Iteration") 55 | re_force = re.compile("TOTAL-FORCE") 56 | re_mag = re.compile("number of electron") 57 | re_volume = re.compile("volume of cell") 58 | 59 | lastenergy = 0.0 60 | energy = 0.0 61 | steps = 1 62 | iterations = 0 63 | cputime = 0.0 64 | totaltime = 0.0 65 | dE = 0.0 66 | magmom = 0.0 67 | spinpolarized = False 68 | volume = 0.0 69 | #average = 0.0 70 | #maxforce = 0.0 71 | 72 | i = 0 73 | for line in outcarlines: 74 | 75 | if re_iteration.search(line): 76 | iterations = iterations + 1 77 | 78 | if re_force.search(line): 79 | # Calculate forces here... 80 | forces = [] 81 | magnitudes = [] 82 | for j in range(natoms): 83 | parts = outcarlines[i+j+2].split() 84 | x = float(parts[3]) 85 | y = float(parts[4]) 86 | z = float(parts[5]) 87 | forces.append([x,y,z]) 88 | magnitudes.append(np.sqrt(x**2 + y**2 + z**2)) 89 | 90 | average = sum(magnitudes)/natoms 91 | maxforce = max(magnitudes) 92 | 93 | if re_mag.search(line): 94 | parts = line.split() 95 | if len(parts) > 5 and parts[0].strip() != "NELECT": 96 | spinpolarized = True 97 | magmom = float(parts[5]) 98 | 99 | if re_volume.search(line): 100 | parts = line.split() 101 | if len(parts) > 4: 102 | volume = float(parts[4]) 103 | 104 | if re_energy.search(line): 105 | lastenergy = energy 106 | energy = float(line.split()[4]) 107 | dE = np.log10(abs(energy-lastenergy+1.0E-12)) 108 | 109 | # CONSTRUCT OUTPUT STRING 110 | try: 111 | stepstr = str(steps).rjust(4) 112 | energystr = f'Energy: {energy:3.6f}'.rjust(12) 113 | logdestr = f'Log|dE|: {dE:1.3f}'.rjust(6) 114 | iterstr = f'SCF: {iterations:3d}' 115 | avgfstr = f'Avg|F|: {average:2.3f}'.rjust(6) 116 | maxfstr = f'Max|F|: {maxforce:2.3f}'.rjust(6) 117 | volstr = f'Vol.: {volume:3.1f}'.rjust(5) 118 | except NameError: 119 | print(f"Cannot understand this OUTCAR file...try to read ahead") 120 | continue 121 | 122 | if iterations == nelmax: 123 | sys.stdout.write(FAIL) 124 | #print " ^--- SCF cycle reached NELMAX. Check convergence!" 125 | 126 | if (dE < ediff): 127 | sys.stdout.write(OKGREEN) 128 | 129 | if spinpolarized: 130 | magstr=f'Mag: {magmom:2.2f}'.rjust(6) 131 | print (f'{stepstr},{energystr},{logdestr},{iterstr},{avgfstr},{maxfstr},{volstr},{magstr}') 132 | else: 133 | print (f'{stepstr},{energystr},{logdestr},{iterstr},{avgfstr},{maxfstr},{volstr}') 134 | 135 | sys.stdout.write(ENDC) 136 | 137 | steps = steps + 1 138 | iterations = 0 139 | totaltime = totaltime + cputime 140 | cputime = 0.0 141 | 142 | i = i + 1 143 | 144 | -------------------------------------------------------------------------------- /get_properties_VASP.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | ''' 4 | #####--------------------------------------------------------- 5 | #####--------------------------------------------------------- 6 | # Credit :Asif Iqbal BHATTI 7 | # CODE to: OBTAIN Elastic properties from OUTCAR file, 8 | # compare POSCAR and CONTCAR volume deformation 9 | # upon minimization, and extract energy from a number 10 | # of directories. extract lattice distortion 11 | # VERSION: This script runs with python3 or later 12 | # FORMAT :POSCAR VASP5 format 13 | # DATE :28/12/2019 14 | # USAGE :python3 sys.argv[0] 15 | # VERSION: 4.0 16 | #####--------------------------------------------------------- 17 | #####--------------------------------------------------------- 18 | ''' 19 | 20 | import os, sys, spglib, scipy 21 | import math, glob 22 | import numpy as np 23 | import subprocess 24 | from os import listdir 25 | from os.path import isfile, join 26 | from pathlib import Path 27 | from termcolor import colored 28 | import multiprocessing as mp 29 | from colorama import Fore, Back, Style, init 30 | from pylab import * 31 | init(autoreset=True) 32 | 33 | 34 | ''' 35 | ##########################--------------------------------------------------------- 36 | # 1- Read only POSCAR file in a given directory & obtain local lattice distortion 37 | ##########################--------------------------------------------------------- 38 | ''' 39 | 40 | def poscar(): 41 | if not os.path.exists('POSCAR'): 42 | print (' ERROR: POSCAR does not exist here.') 43 | sys.exit(0) 44 | print('Reading POSCAR/CONTCAR: \n') 45 | pos = []; kk = []; lattice = []; sum = 0 46 | file = open('POSCAR','r') or open('CONTCAR','r') 47 | 48 | firstline = file.readline() # IGNORE first line comment 49 | secondfline = file.readline() # scale 50 | Latvec1 = file.readline() 51 | #print ("Lattice vector 1:", (Latvec1), end = '') 52 | Latvec2 = file.readline() 53 | #print ("Lattice vector 2:", (Latvec2), end = '') 54 | Latvec3 = file.readline() 55 | #print ("Lattice vector 3:", (Latvec3), end = '') 56 | elementtype=file.readline().split() 57 | if (str.isdigit(elementtype[0])): 58 | sys.exit("VASP 4.X POSCAR detected. Please add the atom types") 59 | print ("Types of elements:", str(elementtype), end = '\n') 60 | numberofatoms=file.readline() 61 | Coordtype=file.readline() 62 | print ("Coordtype:", (Coordtype), end = '\n') 63 | 64 | ########################--------------------------------------------------------- 65 | print (">>>>>>>>>-------------------# of Atoms--------------------") 66 | nat = numberofatoms.split() 67 | nat = [int(i) for i in nat] 68 | print (nat) 69 | for i in nat: 70 | sum = sum + i 71 | numberofatoms = sum 72 | print ("Number of atoms:", (numberofatoms), end = '\n') 73 | ########################--------------------------------------------------------- 74 | 75 | #print (">>>>>>>>>---------------Atomic positions------------------") 76 | for x in range(int(numberofatoms)): 77 | coord = file.readline().split() 78 | coord = [float(i) for i in coord] 79 | pos = pos + [coord] 80 | pos = np.array(pos) 81 | #print (pos) 82 | 83 | file.close() 84 | 85 | ########################--------------------------------------------------------- 86 | a=[]; b=[]; c=[]; 87 | Latvec1=Latvec1.split() 88 | Latvec2=Latvec2.split() 89 | Latvec3=Latvec3.split() 90 | for ai in Latvec1: 91 | a.append(float(ai)) 92 | for bi in Latvec2: 93 | b.append(float(bi)) 94 | for ci in Latvec3: 95 | c.append(float(ci)) 96 | 97 | ########################--------------------------------------------------------- 98 | 99 | print (">>>>>>>>>---------------Lattice vectors distortions-----------------") 100 | lattice = np.array([a] + [b] + [c]) 101 | #determinant = np.linalg.det(lattice) 102 | lld = lattic_distortion.local_lattice_distortion(a,b,c) 103 | print ("lattice distortion parameter g: {}".format(lld) ) 104 | 105 | print (">>>>>>>>>---------------Space group-----------------") 106 | print (" ") 107 | sp, symm = space_group_analyse(lattice, pos) 108 | print ( sp, symm ) 109 | print (" ") 110 | print (">>>>>>>>>--------------------------------------------") 111 | print ('a=', a) 112 | print ('b=', b) 113 | print ('c=', c) 114 | gamma = math.degrees(math.acos(np.dot(a,b) / (np.linalg.norm(a) * np.linalg.norm(b)))) 115 | alpha = math.degrees(math.acos(np.dot(b,c) / (np.linalg.norm(b) * np.linalg.norm(c)))) 116 | beta = math.degrees(math.acos(np.dot(a,c) / (np.linalg.norm(a) * np.linalg.norm(c)))) 117 | print ("ratio c/a = %2f" %(np.linalg.norm(c) / np.linalg.norm(a) )) 118 | print ("-"*100) 119 | print ('||a||=%2f, \u03B1= %2f' %(np.linalg.norm(a), alpha)) 120 | print ('||b||=%2f \u03B2= %2f' %(np.linalg.norm(b), beta)) 121 | print ('||c||=%2f \u03B3= %2f' %(np.linalg.norm(c), gamma)) 122 | print ('Vol= %4.8f A^3; %4.8f [a.u]^3' %(volume(a,b,c,math.radians(alpha),math.radians(beta),math.radians(gamma) ))) 123 | 124 | ### 125 | class lattic_distortion(): 126 | @classmethod 127 | def local_lattice_distortion(a1,b1,c1): 128 | #print ("The lattice distortion in paracrystals is measured by the lattice distortion parameter g") 129 | #print (Back.YELLOW + "Wang, S. Atomic structure modeling of multi-principal-element alloys by the principle") 130 | #print (Back.YELLOW + "of maximum entropy. Entropy 15, 5536–5548 (2013).") 131 | #print ("") 132 | a=np.linalg.norm(a1); b=np.linalg.norm(b1); c=np.linalg.norm(c1) 133 | d = np.array([a,b,c]) 134 | d_mean = np.mean(d); d_std = np.std(d) 135 | d_square_mean = (a**2 + b**2 + c**2)/3 136 | g = np.sqrt( d_square_mean/(d_mean)**2 - 1 ) 137 | return g 138 | ### 139 | 140 | def local_lattice_distortion_DEF1(): 141 | #print ("The lattice distortion in paracrystals is measured by the lattice distortion parameter g") 142 | #print (Back.YELLOW + "Wang, S. Atomic structure modeling of multi-principal-element alloys by the principle") 143 | #print (Back.YELLOW + "of maximum entropy. Entropy 15, 5536–5548 (2013).") 144 | print ("+"*40,"HUME ROTHERY RULE","+"*40) 145 | C_i=C=0.2 ; r_avg = 0.0; del_sum=0.0 146 | elements = ["Nb", "Hf", "Ta", "Ti", "Zr"] 147 | eta = { 148 | "Nb" : 1.98, 149 | "Hf" : 2.08, 150 | "Ta" : 2.00, 151 | "Ti" : 1.76, 152 | "Zr" : 2.06, } 153 | 154 | print (" {element: atomic radius}") 155 | print (eta) 156 | 157 | for i in elements: 158 | r_avg = r_avg + C * eta[i] 159 | 160 | for j in elements: 161 | del_sum = del_sum + C * ( 1 - float(eta[j]) / r_avg )**2 162 | del_sum = 100 * np.sqrt(del_sum) 163 | print("HEA_atomic_size_mismatch: \u03B4={}".format(del_sum)) 164 | ### 165 | 166 | def local_lattice_distortion_DEF2(): 167 | print (">"*10,"local_lattice_distortion_DEF2") 168 | print (" Song, H. et al. Local lattice distortion in high-entropy alloys.") 169 | print (" Phys. Rev. Mater. 1, 23404 (2017).") 170 | print (" (***) Different definition of the atomic radius for the description ") 171 | print (" of the local lattice distortion in HEAs") 172 | 173 | if not os.path.exists('POSCAR' and 'CONTCAR'): 174 | print ('>>> ERROR: POSCAR & CONTCAR does not exist (Both should be in the same directory)') 175 | sys.exit(0) 176 | print('Reading POSCAR and CONTCAR ... \n') 177 | 178 | x = []; y =[]; z=[] 179 | xp =[]; yp = []; zp = []; temp=0 180 | 181 | f = open('POSCAR','r') 182 | lines_poscar = f.readlines() 183 | f.close() 184 | 185 | f = open('CONTCAR','r') 186 | lines_contcar = f.readlines() 187 | f.close() 188 | 189 | file_P = ase.io.read('POSCAR') 190 | pos = file_P.get_cell_lengths_and_angles() 191 | print (CRED + "POSCAR=>Length&Angles->{}".format(pos) + CEND) 192 | file_C = ase.io.read('CONTCAR') 193 | con = file_C.get_cell_lengths_and_angles() 194 | print (CRED + "CONTCAR=>Length&Angles->{}".format(con) + CEND) 195 | print ("Cell vectors difference:: ",con-pos) 196 | 197 | sum_atoms = lines_poscar[6].split() ### reading 7th lines for reading # of atoms 198 | sum_atoms = [int(i) for i in sum_atoms] 199 | sum_atoms = sum(sum_atoms) 200 | 201 | for i in lines_poscar: 202 | if "Direct" in i: 203 | lp=lines_poscar.index(i) 204 | for j in lines_contcar: 205 | if "Direct" in j: 206 | lc=lines_contcar.index(j) 207 | 208 | for i in range(sum_atoms): 209 | x, y, z = lines_poscar[lp+1+i].split() 210 | xc, yc, zc = lines_contcar[lp+1+i].split() 211 | x = float(x); y = float(y); z = float(z) 212 | xc = float(xc); yc = float(yc); zc = float(zc) 213 | temp = temp + np.sqrt( (x-xc)**2 + (y-yc)**2 + (z-zc)**2 ) 214 | temp = temp/sum_atoms 215 | print("local lattice distortion (LLD): \u0394d={}".format(temp)) 216 | 217 | ### 218 | def space_group_analyse(lattice, pos): 219 | numbers = [1,2] 220 | cell = (lattice, pos, numbers) 221 | sp=spglib.get_spacegroup(cell, symprec=1e-5) 222 | symm=spglib.get_symmetry(cell, symprec=1e-5) 223 | #print(spglib.niggli_reduce(lattice, eps=1e-5)) 224 | 225 | #mesh = [8, 8, 8] 226 | #mapping, grid = spglib.get_ir_reciprocal_mesh(mesh, cell, is_shift=[0, 0, 0]) 227 | ## All k-points and mapping to ir-grid points 228 | #for i, (ir_gp_id, gp) in enumerate(zip(mapping, grid)): 229 | # print("%3d ->%3d %s" % (i, ir_gp_id, gp.astype(float) / mesh)) 230 | # 231 | ## Irreducible k-points 232 | #print("Number of ir-kpoints: %d" % len(np.unique(mapping))) 233 | #print(grid[np.unique(mapping)] / np.array(mesh, dtype=float)) 234 | # 235 | ## 236 | ## With shift 237 | ## 238 | #mapping, grid = spglib.get_ir_reciprocal_mesh(mesh, cell, is_shift=[1, 1, 1]) 239 | # 240 | ## All k-points and mapping to ir-grid points 241 | #for i, (ir_gp_id, gp) in enumerate(zip(mapping, grid)): 242 | # print("%3d ->%3d %s" % (i, ir_gp_id, (gp + [0.5, 0.5, 0.5]) / mesh)) 243 | # 244 | ## Irreducible k-points 245 | #print("Number of ir-kpoints: %d" % len(np.unique(mapping))) 246 | #print((grid[np.unique(mapping)] + [0.5, 0.5, 0.5]) / mesh) 247 | return sp, symm 248 | ### 249 | 250 | def poscar_VASP42VASP5(): 251 | if not os.path.exists('POSCAR' and 'POTCAR'): 252 | print (' ERROR: POSCAR does not exist here.') 253 | sys.exit(0) 254 | file1 = open("POSCAR",'r') 255 | line1 = file1.readlines() 256 | file1.close() 257 | 258 | file2 = open("POTCAR",'r') 259 | line2 = file2.readlines() 260 | file2.close() 261 | 262 | atom_number=[] 263 | for i in line1: 264 | if ("Direct" or "direct" or "d" or "D") in i: 265 | PP=line1.index(i) 266 | atom_number = line1[5].split() 267 | print(atom_number) 268 | 269 | elementtype=[]; count=0 270 | for i in line2: 271 | if ("VRHFIN") in i: 272 | count+=1 273 | #print (i.split('=')[1].split(':')[0]) 274 | elementtype.append(i.split('=')[1].split(':')[0]) 275 | 276 | test = open("POSCAR_W",'w') 277 | 278 | for i in range(5): 279 | test.write( line1[i] ) 280 | 281 | for j in elementtype: 282 | test.write("\t" + j) 283 | test.write("\n" ) 284 | 285 | for j in atom_number: 286 | test.write("\t" + j ) 287 | test.write("\n" ) 288 | 289 | test.write("Selective dynamics") 290 | test.write("\n" ) 291 | 292 | for i in range(len(line1)-PP): 293 | test.write(line1[PP+i] ) 294 | 295 | test.close() 296 | 297 | print (" File is converted: POSCAR_W") 298 | ### 299 | 300 | ''' 301 | #####--------------------------------------------------------- 302 | # 2- Looping over all directories containing POSCAR & CONTCAR files 303 | #####--------------------------------------------------------- 304 | ''' 305 | 306 | def main_poscar(): 307 | count = 0 308 | os.system("rm out_POSCARS.dat") 309 | VOL_P = []; pos = []; kk = []; lattice = []; 310 | mypath = os.getcwd() 311 | print ("-"*100) 312 | print (Back.YELLOW + "{:15s} {:15s} {:15.6s} {:15.6s} {:15.6s} {:15.15s}".format("Directory", "# of atoms", "||a||", \ 313 | "||b||", "||c||", "VOL_POS[A^3]"),end="\n" ) 314 | print ("-"*100) 315 | 316 | for entry in os.listdir(mypath): 317 | if os.path.isdir(os.path.join(mypath, entry)): 318 | #print (entry) 319 | for file in os.listdir(entry): 320 | if file == "POSCAR": 321 | count+=1; sum = 0 322 | filepath = os.path.join(entry, file) 323 | #f = open(filepath, 'r') 324 | #print (f.read()) 325 | #f.close() 326 | fo = open(filepath, 'r') 327 | ofile=open('out_POSCARS.dat','a') 328 | 329 | #print (colored('>>>>>>>> Name of the file: ','red'), fo.name, end = '\n', flush=True) 330 | 331 | ofile.write (fo.name + '\n') 332 | ofile.write ("") 333 | firstline = fo.readline() 334 | secondfline = fo.readline() 335 | Latvec1 = fo.readline() 336 | #print ("Lattice vector 1:", (Latvec1), end = '') 337 | #ofile.write (Latvec1) 338 | Latvec2 = fo.readline() 339 | #print ("Lattice vector 2:", (Latvec2), end = '') 340 | #ofile.write (Latvec2) 341 | Latvec3 = fo.readline() 342 | #print ("Lattice vector 3:", (Latvec3), end = '') 343 | #ofile.write (Latvec3) 344 | elementtype=fo.readline() 345 | elementtype = elementtype.split() 346 | #print ("Types of elements:", str(elementtype), end = '') 347 | #ofile.write (str(elementtype)) 348 | numberofatoms=fo.readline() 349 | #print ("Number of atoms:", (numberofatoms), end = '') 350 | #ofile.write ((numberofatoms)) 351 | Coordtype=fo.readline() 352 | 353 | ##########################--------------------------------------------------------- 354 | #print ("**********-------------------# of Atoms--------------------") 355 | 356 | nat = numberofatoms.split() 357 | nat = [int(i) for i in nat] 358 | for i in nat: 359 | sum = sum + i 360 | numberofatoms = sum 361 | #print ("{} :: Number of atoms: {}".format(nat, numberofatoms) ) 362 | ##########################--------------------------------------------------------- 363 | #print ("-----------------------Atomic positions-----------------") 364 | #print ("Coordtype:", (Coordtype), end = '') 365 | for x in range(int(numberofatoms)): 366 | coord = fo.readline().split() 367 | coord = [float(i) for i in coord] 368 | pos = pos + [coord] 369 | pos = np.array(pos) 370 | #print (pos) 371 | 372 | ofile.write ("\n") 373 | fo.close() 374 | ##########################--------------------------------------------------------- 375 | 376 | a=[]; b=[]; c=[]; 377 | Latvec1=Latvec1.split() 378 | Latvec2=Latvec2.split() 379 | Latvec3=Latvec3.split() 380 | 381 | ##########################--------------------------------------------------------- 382 | for ai in Latvec1: a.append(float(ai)) 383 | for bi in Latvec2: b.append(float(bi)) 384 | for ci in Latvec3: c.append(float(ci)) 385 | #print ('a=', a) 386 | ofile.write ("'a=' {}\n".format(a)) 387 | #print ('b=', b) 388 | ofile.write ("'b=' {}\n".format(b)) 389 | #print ('c=', c) 390 | ofile.write ("'c=' {}\n".format(c)) 391 | lld = lattic_distortion.local_lattice_distortion(a,b,c) 392 | ##########################--------------------------------------------------------- 393 | 394 | alpha, beta, gamma = lattice_angles(a,b,c) 395 | VOL_POS = np.dot(a, np.cross(b,c)) 396 | VOL_P.append(VOL_POS) 397 | 398 | ofile.write ("'\u03B1=' {} '\u03B2=' {} '\u03B3=' {}\n".format(alpha,beta,gamma)) 399 | ofile.write ("'||a||=' {}\n".format(np.linalg.norm(a))) 400 | ofile.write ("'||b||=' {}\n".format(np.linalg.norm(b))) 401 | ofile.write ("'||c||=' {}\n".format(np.linalg.norm(c))) 402 | #print ("#####------------------------------------------------") 403 | 404 | #print ("a={} \t ||a||={:10.6f}".format(a, np.linalg.norm(a)) ) 405 | #print ("b={} \t ||b||={:10.6f}".format(b, np.linalg.norm(b)) ) 406 | #print ("c={} \t ||c||={:10.6f}".format(c, np.linalg.norm(c)) ) 407 | print ("{:15s} {:6d} {:15.6f} {:15.6f} {:15.6f} {:15.6f}".format(fo.name, numberofatoms, np.linalg.norm(a), \ 408 | np.linalg.norm(b), np.linalg.norm(c), VOL_POS) ) 409 | 410 | print ("'\u03B1=' {:6.6f} '\u03B2=' {:6.6f} '\u03B3=' {:6.6f} g={:6.6f}".format(alpha,beta,gamma,lld)) 411 | print ("."*5) 412 | #print ('Vol= {:6.6f} A^3'.format(VOL_POS)) 413 | ofile.write ("***************************************************\n") 414 | ofile.close() 415 | print ("_"*30) 416 | print ("Number of folders detected: ", count) 417 | return VOL_P 418 | 419 | #### 420 | def main_contcar(): 421 | count = 0 422 | os.system("rm out_CONTCARS.dat") 423 | VOL_C = []; pos = []; kk = []; lattice = []; sum = 0 424 | mypath = os.getcwd() 425 | print ("-"*100) 426 | print (Back.GREEN + "{:15s} {:15s} {:15.6s} {:15.6s} {:15.6s} {:15.15s}".format("Directory", "# of atoms", "||a||", \ 427 | "||b||", "||c||", "VOL_CON[A^3]"),end="\n" ) 428 | print ("-"*100) 429 | print(Style.RESET_ALL) 430 | for entry in os.listdir(mypath): 431 | if os.path.isdir(os.path.join(mypath, entry)): 432 | for file in os.listdir(entry): 433 | 434 | if file == "CONTCAR": 435 | count+=1; sum = 0 436 | filepath = os.path.join(entry, file) 437 | fo = open(filepath, 'r') 438 | 439 | ofile=open('out_CONTCARS.dat','a') 440 | 441 | #print (colored('>>>>>>>> Name of the file: ','yellow'), fo.name, end = '\n', flush=True) 442 | ofile.write (fo.name + '\n') 443 | ofile.write ("") 444 | firstline = fo.readline() 445 | secondfline = fo.readline() 446 | Latvec1 = fo.readline() 447 | Latvec2 = fo.readline() 448 | Latvec3 = fo.readline() 449 | elementtype=fo.readline() 450 | elementtype = elementtype.split() 451 | numberofatoms=fo.readline() 452 | Coordtype=fo.readline() 453 | #print ("Coordtype:", (Coordtype), end = '') 454 | ##########################--------------------------------------------------------- 455 | #print ("**********-------------------# of Atoms--------------------") 456 | 457 | nat = numberofatoms.split() 458 | nat = [int(i) for i in nat] 459 | for i in nat: 460 | sum = sum + i 461 | numberofatoms = sum 462 | #print ("{} :: Number of atoms: {}".format(nat, numberofatoms) ) 463 | ##########################--------------------------------------------------------- 464 | #print ("//////---------------Atomic positions-----------------") 465 | for x in range(int(numberofatoms)): 466 | coord = fo.readline().split() 467 | coord = [float(i) for i in coord] 468 | pos = pos + [coord] 469 | pos = np.array(pos) 470 | #print (pos) 471 | 472 | ofile.write ("\n") 473 | fo.close() 474 | ##########################--------------------------------------------------------- 475 | a=[]; b=[]; c=[]; 476 | Latvec1=Latvec1.split() 477 | Latvec2=Latvec2.split() 478 | Latvec3=Latvec3.split() 479 | ##########################--------------------------------------------------------- 480 | for ai in Latvec1: a.append(float(ai)) 481 | for bi in Latvec2: b.append(float(bi)) 482 | for ci in Latvec3: c.append(float(ci)) 483 | #print ('a=', a) 484 | ofile.write ("'a=' {}\n".format(a)) 485 | #print ('b=', b) 486 | ofile.write ("'b=' {}\n".format(b)) 487 | #print ('c=', c) 488 | ofile.write ("'c=' {}\n".format(c)) 489 | lld = lattic_distortion.local_lattice_distortion(a,b,c) 490 | ##########################--------------------------------------------------------- 491 | 492 | alpha, beta, gamma = lattice_angles(a,b,c) 493 | VOL_CON = np.dot(a, np.cross(b,c)) 494 | VOL_C.append(VOL_CON) 495 | 496 | ofile.write ("'\u03B1=' {} '\u03B2=' {} '\u03B3=' {}\n".format(alpha,beta,gamma)) 497 | ofile.write ("'||a||=' {}\n".format(np.linalg.norm(a))) 498 | ofile.write ("'||b||=' {}\n".format(np.linalg.norm(b))) 499 | ofile.write ("'||c||=' {}\n".format(np.linalg.norm(c))) 500 | #print ("-"*80) 501 | 502 | #print ("a={} \t ||a||={:10.6f}".format(a, np.linalg.norm(a)) ) 503 | #print ("b={} \t ||b||={:10.6f}".format(b, np.linalg.norm(b)) ) 504 | #print ("c={} \t ||c||={:10.6f}".format(c, np.linalg.norm(c)) ) 505 | print ("{:15s} {:6d} {:15.6f} {:15.6f} {:15.6f} {:15.6f}".format(fo.name, numberofatoms, np.linalg.norm(a), \ 506 | np.linalg.norm(b), np.linalg.norm(c), VOL_CON) ) 507 | 508 | print ("'\u03B1=' {:6.6f} '\u03B2=' {:6.6f} '\u03B3=' {:6.6f} g={:6.6f}".format(alpha,beta,gamma,lld)) 509 | print ("."*5) 510 | #print ('Vol= {:6.6f} A^3'.format(VOL_CON), end="\n") 511 | ofile.write ("***************************************************\n") 512 | ofile.close() 513 | #print (VOL_C) 514 | print ("-"*80) 515 | print ("Number of folders detected: ", count) 516 | return VOL_C 517 | 518 | #### math.sin function takes argument in radians ONLY 519 | def volume(a,b,c,alpha,beta,gamma): 520 | ang2atomic = 1.889725988579 # 1 A = 1.889725988579 [a.u] 521 | Ang32Bohr3 = 6.74833304162 # 1 A^3 = 6.7483330371 [a.u]^3 522 | 523 | length = np.linalg.norm(a) * np.linalg.norm(b) * np.linalg.norm(c) 524 | volume = length * ( np.sqrt(1 + 2 * math.cos(alpha) * math.cos(beta) * math.cos(gamma) - math.cos(alpha)**2 - math.cos(beta)**2 - math.cos(gamma)**2) ) 525 | vol_au = volume * Ang32Bohr3 526 | return volume, vol_au 527 | 528 | #### Ordering of returning angles variables does matter 529 | def lattice_angles(a,b,c): 530 | ### gamma = Cos-1( (a.b)/||a||.||b|| ) 531 | ### alpha = Cos-1( (b.c)/||b||.||c|| ) 532 | ### beta = Cos-1( (a.c)/||a||.||c|| ) 533 | gamma = math.degrees(math.acos(np.dot(a,b) / (np.linalg.norm(a) * np.linalg.norm(b)))) 534 | alpha = math.degrees(math.acos(np.dot(b,c) / (np.linalg.norm(b) * np.linalg.norm(c)))) 535 | beta = math.degrees(math.acos(np.dot(a,c) / (np.linalg.norm(a) * np.linalg.norm(c)))) 536 | return alpha, beta, gamma 537 | 538 | ####### BASH way of finding the # of directories in a working directory ### 539 | def volume_diff(VOL_P, VOL_C): 540 | n=os.popen("find . -mindepth 1 -maxdepth 1 -type d | wc -l").read() 541 | print ("-"*80) 542 | print ("VOL Diff A^3 %18s %12s %15.15s" %("CONTCAR", "POSCAR", "contcar-poscar")) 543 | print ("-"*80) 544 | for i in range(int(n)): 545 | print ("The difference is: %12.6f %12.6f %15.8f " %(VOL_C[i], VOL_P[i], VOL_C[i] - VOL_P[i]) ) 546 | 547 | #### 548 | 549 | ''' 550 | #####--------------------------------------------------------- 551 | # 3- ELASTIC PROPERTIES from VASP OUTCAR file "STRESS APPROACH" 552 | #####--------------------------------------------------------- 553 | ''' 554 | 555 | class Elastic_Matrix: 556 | def print_Cij_Matrix(): ###EXERCISE 557 | Bij = []; C = "C" 558 | for i in range(0, 6, 1): 559 | Bij.append([]) 560 | for j in range(1,7, 1): 561 | Bij[i].append((C + str(i+1) + str(j))) 562 | l = np.matrix(Bij) 563 | return l 564 | 565 | def langragian_strain(): 566 | kk = ('x', 'y', 'z'); C = "E"; Eij=[] 567 | eta = { 568 | "xx" : 11, 569 | "yy" : 22, 570 | "zz" : 33, 571 | "yz" : 23, 572 | "xz" : 13, 573 | "xy" : 12 } 574 | print ( "The Langragian strain in Voigt notation: ") 575 | print ( eta.items()) 576 | 577 | for n in kk: 578 | for m in kk: 579 | Eij.append( (C + str(n) + str(m)) ) 580 | ls = np.matrix(Eij).reshape(3,3) 581 | return ls 582 | 583 | ### 584 | def elastic_matrix_VASP_STRESS(): 585 | while True: 586 | if not os.path.exists('OUTCAR'): 587 | print (' ERROR: OUTCAR does not exist here.') 588 | sys.exit(0) 589 | 590 | s=np.zeros((6,6)) 591 | c=np.zeros((6,6)) 592 | file = open("OUTCAR",'r') 593 | lines = file.readlines() 594 | file.close() 595 | 596 | for i in lines: 597 | if "TOTAL ELASTIC MODULI (kBar)" in i: 598 | ll=lines.index(i) 599 | if "LATTYP" in i: 600 | crystaltype=str(i.split()[3]) 601 | print ("DETECTED CRYSTAL FROM OUTCAR:", crystaltype) 602 | print (" ") 603 | for i in range(0,6): 604 | l=lines[ll+3+i] # indexing a line in huge file 605 | word = l.split() 606 | s[i][:] = word[1:7] 607 | for j in range(0,6): 608 | c[i][j] = float(s[i][j])/10.0 609 | 610 | ##########-------------------stress tensor------------------ 611 | 612 | Cij = np.matrix(c) 613 | np.set_printoptions(precision=4, suppress=True) 614 | print (Cij) 615 | print(Elastic_Matrix.print_Cij_Matrix() ) 616 | print(Elastic_Matrix.langragian_strain() ) 617 | print ("\nEigen Values of the matrix Cij:") 618 | evals = np.linalg.eigvals(Cij) 619 | if evals.all() > 0: 620 | print(evals) 621 | print("All Eigen values are positive") 622 | 623 | ##########-------------------Compliance tensor------------------ 624 | ##########------------------- s_{ij} = C_{ij}^{-1} 625 | 626 | Sij = np.linalg.inv(Cij) 627 | 628 | #---------------------------- ELASTIC PROPERTIES ----------------------------------- 629 | 630 | stability_test(Cij, crystaltype) 631 | 632 | #------------------------------- Voigt bulk modulus K_v $(GPa)$--------------- 633 | #------------------ 9K_v = (C_{11}+C_{22}+C_{33}) + 2(C_{12} + C_{23} + C_{31}) 634 | Kv = ((Cij[0,0] + Cij[1,1] + Cij[2,2]) + 2 * (Cij[0,1] + Cij[1,2] + Cij[2,0]))/9.0 635 | #------------------------------- Reuss shear modulus G_v $(GPa)$------------------ 636 | #------------------ 15/G_R = 4(s_{11}+s_{22}+s_{33}) - 4(s_{12} + s_{23} + s_{31}) + 3(s_{44} + s_{55} + s_{66})$ 637 | Gv = ((Cij[0,0] + Cij[1,1] + Cij[2,2]) - (Cij[0,1] + Cij[1,2] + Cij[2,0]) + 3 * (Cij[3,3] + Cij[4,4] + Cij[5,5]))/15.0 638 | #------------------------------- Reuss bulk modulus K_r $(GPa)$---------------- 639 | #------------------ 1/K_R = (s_{11}+s_{22}+s_{33}) + 2(s_{12} + s_{23} + s_{31})$ 640 | Kr = 1/((Sij[0,0] + Sij[1,1] + Sij[2,2]) + 2 * (Sij[0,1] + Sij[1,2] + Sij[2,0]) ) 641 | #------------------------------- Reuss shear modulus G_r $(GPa)$------------------ 642 | Gr = 15/(4 * (Sij[0,0] + Sij[1,1] + Sij[2,2]) - 4 * (Sij[0,1] + Sij[1,2] + Sij[2,0]) + 3 * (Sij[3,3] + Sij[4,4] + Sij[5,5])) 643 | 644 | #----------------------------------------------------------------------------------- 645 | 646 | ## Young's Modulus "E": Voigt 647 | Ev = (9*Kv*Gv)/(3*Kv + Gv) 648 | ## Young's: Reuss 649 | Er = (9*Kr*Gr)/(3*Kr + Gr) 650 | 651 | ## Poisson's ratio: Voigt 652 | Nu_V = (3*Kv - Ev)/(6*Kv) 653 | ## Poisson's ratio: Reuss 654 | Nu_R = (3*Kr - Er)/(6*Kr) 655 | 656 | ## P-wave modulus, M: Voigt 657 | MV = Kv + (4*Gv/3.0) 658 | ## P-wave modulus, M: Reuss 659 | MR = Kr + (4*Gr/3.0) 660 | 661 | #----------------------------------------------------------------------------------- 662 | #-------------- Voigt-Reuss-Hill Approximation: average of both methods 663 | Kvrh = (Kv + Kr)/2.0 664 | Gvrh = (Gv + Gr)/2.0 665 | Mvrh = (MV + MR)/2.0 666 | Evrh = (Ev + Er)/2.0 667 | Nu_vrh = (Nu_V + Nu_R)/2.0 668 | KG_ratio_V = Kv/Gv 669 | KG_ratio_R = Kr/Gr 670 | KG_ratio_vrh = Kvrh/Gvrh 671 | #-------------- Isotropic Poisson ratio $\mu 672 | #-------------- $\mu = (3K_{vrh} - 2G_{vrh})/(6K_{vrh} + 2G_{vrh})$ 673 | mu = (3 * Kvrh - 2 * Gvrh) / (6 * Kvrh + 2 * Gvrh ) 674 | 675 | #---------------------------------------------------------------------- 676 | #----------------------------------------------------------------------------------- 677 | 678 | print ("\n \n Voigt Reuss Average") 679 | print ("-------------------------------------------------------") 680 | print ("Bulk modulus (GPa) %9.3f %9.3f %9.3f " % (Kv, Kr, Kvrh)) 681 | print ("Shear modulus (GPa) %9.3f %9.3f %9.3f " % (Gv, Gr, Gvrh)) 682 | print ("Young modulus (GPa) %9.3f %9.3f %9.3f " % (Ev, Er, Evrh)) 683 | print ("Poisson ratio %9.3f %9.3f %9.3f " % (Nu_V, Nu_R, Nu_vrh)) 684 | print ("P-wave modulus (GPa) %9.3f %9.3f %9.3f " % (MV, MR, Mvrh)) 685 | print ("Bulk/Shear ratio %9.3f %9.3f %9.3f (%s) " %(KG_ratio_V, KG_ratio_R, KG_ratio_vrh, ductile_test(KG_ratio_vrh) )) 686 | print ("-------------------------------------------------------") 687 | print("Isotropic Poisson ratio: ", mu) 688 | break 689 | 690 | ### 691 | def ductile_test(ratio): 692 | if(ratio > 1.75): 693 | return "ductile" 694 | else: 695 | return "brittle" 696 | ### 697 | 698 | def stability_test(matrix, crystaltype): 699 | c = np.copy(matrix) 700 | 701 | if(crystaltype =="cubic"): 702 | print ("Cubic crystal system \n") 703 | print ("Born stability criteria for the stability of cubic system are : \ [Ref- Mouhat and Coudert, PRB 90, 224104 (2014)] \n") 704 | print ("(i) C11 - C12 > 0; (ii) C11 + 2C12 > 0; (iii) C44 > 0 \n ") 705 | 706 | ## check (i) keep in mind list starts with 0, so c11 is stored as c00 707 | if(c[0][0] - c[0][1] > 0.0): 708 | print ("Condition (i) satisfied.") 709 | else: 710 | print ("Condition (i) NOT satisfied.") 711 | 712 | if(c[0][0] + 2*c[0][1] > 0.0): 713 | print ("Condition (ii) satified.") 714 | else: 715 | print ("Condition (ii) NOT satisfied.") 716 | 717 | if(c[3][3] > 0.0): 718 | print ("Condition (iii) satified.") 719 | else: 720 | print ("Condition (iii) NOT satisfied.") 721 | 722 | if(crystaltype =="hexagonal"): 723 | print ("Hexagonal crystal system \n") 724 | print ("Born stability criteria for the stability of hexagonal system are \: [Ref- Mouhat and Coudert, PRB 90, 224104 (2014)] \n") 725 | print ("(i) C11 - C12 > 0; (ii) 2*C13^2 < C33(C11 + C12); (iii) C44 > 0 \n ") 726 | 727 | ## check (i) keep in mind list starts with 0, so c11 is stored as c00 728 | if(c[0][0] - c[0][1] > 0.0): 729 | print ("Condition (i) satisfied.") 730 | else: 731 | print ("Condition (i) NOT satisfied.") 732 | 733 | if(2*(c[0][2]*c[0][2]) < c[2][2]*(c[0][0] + c[0][1])): 734 | print ("Condition (ii) satified.") 735 | else: 736 | print ("Condition (ii) NOT satisfied.") 737 | 738 | if(c[3][3] > 0.0): 739 | print ("Condition (iii) satified.") 740 | else: 741 | print ("Condition (iii) NOT satisfied.") 742 | ### 743 | 744 | def born_stability_criterion(): 745 | print ("Born stability criteria for the stability of following systems \n") 746 | print ("Cubic crystal system.... \n") 747 | print ("(i) C11 - C12 > 0; (ii) C11 + 2C12 > 0; (iii) C44 > 0 \n ") 748 | print ("Hexagonal crystal system.... \n") 749 | print ("(i) C11 - C12 > 0; (ii) 2*C13^2 < C33(C11 + C12); (iii) C44 > 0 \n ") 750 | print ("Tetragonal crystal system.... \n") 751 | print ("(i) C11 - C12 > 0; (ii) 2*C13^2 < C33(C11 + C12); (iii) C44 > 0; (iv) C66 > 0; (v) 2C16^2 < C66*(C11-C12) \n ") 752 | print ("rhombohedral crystal system.... \n") 753 | print ("(i) C11 - C12 > 0; (ii) C13^2 < (1/2)*C33(C11 + C12); (iii) C14^2 < (1/2)*C44*(C11-C12) = C44*C66; (iv) C44 > 0; \n ") 754 | print ("orthorhombic crystal system.... \n") 755 | print ("(i) C11 > 0; (ii) C11*C22 > C12^2; (iii) C11*C22*C33 + 2C12*C13*C23 - C11*C23^2 - C22*C13^2 - C33*C12^2 > 0; (iv) C44 > 0; (v) C55 > 0 ; (vi) C66 > 0 \n") 756 | print ("Monoclinic crystal system.... \n") 757 | print ("[Ref- Mouhat and Coudert, PRB 90, 224104 (2014), and Wu et al. PRB 76, 054115 (2007)] \n") 758 | print ("(i) C11 > 0; (ii) C22 > 0; (iii) C33 > 0; (iv) C44 > 0; (v) C55 > 0 ; (vi) C66 > 0 ") 759 | print ("(vii) [C11 + C22 + C33 + 2*(C12 + C13 + C23)] > 0; (viii) C33*C55 - C35^2 > 0; (ix) C44*C66 - C46^2 > 0; (x) C22 + C33 - 2*C23 > 0 ") 760 | print ("(xi) C22*(C33*C55 - C35^2) + 2*C23*C25*C35 - (C23^2)*C55 - (C25^2)*C33 > 0 ") 761 | print ("(xii) 2*[C15*C25*(C33*C12 - C13*C23) + C15*C35*(C22*C13 - C12*C23) + C25*C35*(C11*C23 - C12*C13)] - [C15*C15*(C22*C33 - C23^2) + C25*C25*(C11*C33 - C13^2) + C35*C35*(C11*C22 - C12^2)] + C55*g > 0 ") 762 | print (" where, g = [C11*C22*C33 - C11*C23*C23 - C22*C13*C13 - C33*C12*C12 + 2*C12*C13*C23 ] " ) 763 | ### 764 | 765 | ''' 766 | #####--------------------------------------------------------- 767 | # 4- CREATE ENERGY vs VOLUME file from VASP OUTCAR file "STRAIN APPROACH" 768 | #####--------------------------------------------------------- 769 | ''' 770 | 771 | def create_energy_vs_volume(): 772 | import fnmatch 773 | mypath = os.getcwd() 774 | os.system("rm energy-vs-volume energy-vs-strain") 775 | eV2Hartree=0.036749309 776 | Ang32Bohr3=6.74833304162 777 | 778 | E=[]; dir_list=[]; count = 0; dir_E=[]; 779 | vol_cell=[]; strain_file=[]; strain_value=[] # strain_value is deformation 780 | 781 | print (" >>>>> Extracting Energies from directories <<<<<<") 782 | for entry in os.listdir(mypath): 783 | if not os.path.exists('strain-01'): 784 | print (' ERROR: strain-* files does not exist. create a strain file for each deformation values.') 785 | sys.exit(0) 786 | if fnmatch.fnmatchcase(entry,'strain-*'): 787 | f = open(entry,'r') 788 | lines = f.readline() #Read first line only 789 | strain_value.append( float(lines) ) 790 | f.close() 791 | if os.path.isfile(os.path.join(mypath, entry)): 792 | strain_file.append(entry) 793 | 794 | if os.path.isdir(os.path.join(mypath, entry)): 795 | dir_list.append(entry) 796 | 797 | for file in os.listdir(entry): 798 | if file == "OUTCAR": 799 | filepath = os.path.join(entry, file) 800 | if not os.path.exists(filepath): 801 | print (' ERROR: OUTCAR does not exist here.') 802 | sys.exit(0) 803 | f = open(filepath,'r') 804 | lines = f.readlines() 805 | f.close() 806 | 807 | for i in lines: 808 | if " free energy TOTEN =" in i: 809 | m=float(i.split()[4]) 810 | if " volume of cell :" in i: 811 | v=float(i.split()[4]) 812 | vol_cell.append(v) 813 | E.append(m) 814 | count+=1 815 | print("# of folders detected: ", count) 816 | print ("Directory :%10.6s %14s %18s %25.20s " % ("Folder", "Energy(eV)", "Vol_of_cell(A^3)", "strain_deformation" )) 817 | 818 | for i in range(math.floor(count/2)): # 0 to 4 819 | print ("Folder name: %10.10s %16.8f %16.8f %16.12s %14.4f" %(dir_list[i], E[i], vol_cell[i], strain_file[i], strain_value[i] )) 820 | if (bool(math.floor(count/2))): 821 | i = math.floor(count/2) 822 | print(Back.GREEN + 'Folder name: %10.10s %16.8f %16.8f %16.12s %14.4f <--Ref' % (dir_list[i], E[i], vol_cell[i], strain_file[i], strain_value[i] )) 823 | print(Style.RESET_ALL, end="") 824 | for i in range(math.ceil(count/2), count, 1): 825 | print ("Folder name: %10.10s %16.8f %16.8f %16.12s %14.4f" %(dir_list[i], E[i], vol_cell[i], strain_file[i], strain_value[i] )) 826 | #rc = subprocess.Popen(['bash', 'extract_energy.sh']) 827 | 828 | print (colored('ENERGIES & VOLUMES ARE WRITTEN IN ATOMIC UNITS TO A FILE ','yellow'), end = '\n', flush=True) 829 | print (colored('IT WILL BE READ BY ELASTIC SCRIPTS FOR POSTPROCESSING eV-->Ha; A^3-->Bohr^3','yellow'), end = '\n', flush=True) 830 | 831 | file = open("energy-vs-volume",'w') 832 | for i in range(count): 833 | file.write ("%14.6f %14.6f\n" %(vol_cell[i] * Ang32Bohr3, E[i] * eV2Hartree)) 834 | file.close() 835 | 836 | file = open("energy-vs-strain",'w') 837 | for i in range(count): 838 | file.write ("%12.6f %14.6f\n" %(strain_value[i], E[i] * eV2Hartree)) 839 | file.close() 840 | ### 841 | 842 | ''' 843 | #####--------------------------------------------------------- 844 | # 5- FITTING ENERGY vs VOLUME CURVE from VASP OUTCAR file 845 | #####--------------------------------------------------------- 846 | ''' 847 | 848 | ### 849 | def fitting_energy_vs_volume_curve_ELASTIC(): 850 | from sys import stdin 851 | import matplotlib.pyplot as plt 852 | import matplotlib.ticker as ptk 853 | import pylab as pyl 854 | import matplotlib.style 855 | 856 | bohr_radius = 0.529177 857 | bohr32ang3 = 0.14818474347 858 | joule2hartree = 4.3597482 859 | joule2rydberg = joule2hartree/2. 860 | unitconv = joule2hartree/bohr_radius**3*10.**3 861 | 862 | if (str(os.path.exists('energy-vs-volume'))=='False'): 863 | sys.exit("ERROR: file energy-vs-volume not found!\n") 864 | energy = []; volume = [] 865 | read_energy = open('energy-vs-volume',"r") 866 | 867 | while True: 868 | line = read_energy.readline() 869 | line = line.strip() 870 | if len(line) == 0: break 871 | energy.append(float(line.split()[1])) 872 | volume.append(float(line.split()[0])) 873 | volume,energy=sortvolume(volume,energy) 874 | 875 | print ("===============================") 876 | print ("Lattice symmetry codes" ) 877 | print ("-------------------------------") 878 | print ("1 --> Simple cubic (sc)" ) 879 | print ("2 --> Body-centered cubic (bcc)") 880 | print ("3 --> Face-centered cubic (fcc)") 881 | print ("-------------------------------") 882 | print ("0 --> Others") 883 | print ("===============================\n") 884 | scheck = input("Enter lattice symmetry code [default 0] >>>> ").replace(" ", "") 885 | 886 | ''' 887 | These factors are for the conversion from the conventional cell to primitive cell 888 | BCC: (a^3)/2 primitive cell volume 889 | FCC: (a^3)/4 primitive cell volume 890 | 891 | ''' 892 | 893 | isym = 0; factor = 1 894 | if ( scheck == "1" ): isym = 1 ; factor=1 ; slabel = "(sc) " 895 | if ( scheck == "2" ): isym = 2 ; factor=2 ; slabel = "(bcc)" 896 | if ( scheck == "3" ): isym = 3 ; factor=4 ; slabel = "(fcc)" 897 | print ("Verification lattice symmetry code >>>> %d " %(isym) ) 898 | #------------------------------------------------------------------------------- 899 | print ('%s' %('-'*105) ) 900 | print ('%20.25s %29.30s %21.30s %11.12s %18.30s' %("Opt_vol Bohr^3 (Ang^3)", "Lattice_const Bohr (A)", "Bulk_modulus [GPa]", "Log(chi)", "Polynomial_order")) 901 | print ('%s' %('-'*105) ) 902 | for order_of_fit in range(2, 11): #order of polynomial fitting 903 | if order_of_fit % 2 == 0: 904 | order_of_fit = int(order_of_fit) 905 | fitr = np.polyfit(volume,energy,order_of_fit) 906 | curv = np.poly1d(fitr) 907 | oned = np.poly1d(np.polyder(fitr,1)) # 908 | bulk = np.poly1d(np.polyder(fitr,2)) 909 | bpri = np.poly1d(np.polyder(fitr,3)) # 910 | vmin = np.roots(np.polyder(fitr)) 911 | dmin=[] 912 | for i in range(len(vmin)): 913 | if (abs(vmin[i].imag) < 1.e-10): 914 | if (volume[0] <= vmin[i] and vmin[i] <= volume[-1]): 915 | if(bulk(vmin[i]) > 0): dmin.append(vmin[i].real) 916 | 917 | xvol = np.linspace(volume[0],volume[-1],100) 918 | if (len(dmin) > 1): print ("WARNING: Multiple minima are found!\n") 919 | if (len(dmin) == 0): print ("WARNING: No minimum in the given xrange!\n") 920 | 921 | chi = 0 922 | for i in range(len(energy)): 923 | chi=chi+(energy[i]-curv(volume[i]))**2 924 | chi=math.sqrt(chi)/len(energy) 925 | #------------------------------------------------------------------------------- 926 | for i in range(len(dmin)): 927 | x0=dmin[len(dmin)-1-i] 928 | v0=dmin[len(dmin)-1-i] 929 | a0=(factor*v0)**(0.33333333333) 930 | b0=bulk(v0)*v0*unitconv 931 | #if (isym > 0): print ('Lattice constant = %5s %12.6f %12.6f' %(slabel,a0, a0*bohr_radius), '[Bohr, Angstrom]') 932 | if (isym > 0): 933 | print("%12.6f (%11.6f) %12.6f (%9.6f) %17.6f %13.2f %10d\n" %(v0, v0*bohr32ang3, a0, a0*bohr_radius, b0, math.log10(chi), order_of_fit), end="") 934 | else: 935 | print("%12.6f(%12.6f) %12.6f(%12.6f) %17.6f %13.2f %10d\n" %(v0, v0*bohr32ang3, a0, a0*bohr_radius, b0, math.log10(chi), order_of_fit), end="") 936 | print ('%s' %('-'*105) ) 937 | #------------------------------------------------------------------------------- 938 | 939 | xlabel = u'Volume [Bohr\u00B3]'; ylabel = r'Energy [Ha]' 940 | 941 | fontlabel=20 942 | fonttick=14 943 | 944 | params = {'ytick.minor.size': 6, 945 | 'xtick.major.pad': 8, 946 | 'ytick.major.pad': 4, 947 | 'patch.linewidth': 2., 948 | 'axes.linewidth': 2., 949 | 'lines.linewidth': 1.8, 950 | 'lines.markersize': 8.0, 951 | 'axes.formatter.limits': (-4, 6)} 952 | 953 | plt.rcParams.update(params) 954 | plt.subplots_adjust(left=0.21, right=0.93, 955 | bottom=0.18, top=0.88, 956 | wspace=None, hspace=None) 957 | 958 | yfmt = ptk.ScalarFormatter(useOffset=True,useMathText=True) 959 | 960 | figure = plt.figure(1, figsize=(9,9)) 961 | ax = figure.add_subplot(111) 962 | ax.text(0.5,-0.18,xlabel,size=fontlabel, transform=ax.transAxes,ha='center',va='center') 963 | ax.text(-0.25,0.5,ylabel,size=fontlabel, transform=ax.transAxes,ha='center',va='center',rotation=90) 964 | for line in ax.get_xticklines() + ax.get_yticklines(): 965 | line.set_markersize(6) 966 | line.set_markeredgewidth(2) 967 | plt.xticks(size=fonttick) 968 | plt.yticks(size=fonttick) 969 | pyl.grid(True) 970 | ############*************************************************************************** 971 | 972 | file=open("tmp","w") 973 | for j in range( len(xvol) ): 974 | file.write("{:12.8f} {} {:12.8f}\n".format(xvol[j]," ",curv(xvol[j]) ) ) 975 | #for i in range( len(strain) ): 976 | # file.write( "{} {}\n".format(strain[i],energy[i]) ) 977 | file.close() 978 | 979 | os.system("paste -d ' ' tmp energy-vs-volume > volume.dat ") 980 | #subprocess.call(("paste -d tmp energy-vs-volume > volume.dat "), shell = True) 981 | os.system("rm tmp") 982 | 983 | ############*************************************************************************** 984 | plt.plot(xvol,curv(xvol),'b-',label='n='+str(order_of_fit)+' fit') 985 | plt.plot(volume,energy,'go',label='calculated') 986 | plt.plot(dmin,curv(dmin),'ro') 987 | plt.legend(loc=9,borderaxespad=.8,numpoints=1) 988 | 989 | ymax = max(max(curv(xvol)),max(energy)) 990 | ymin = min(min(curv(xvol)),min(energy)) 991 | dxx = abs(max(xvol)-min(xvol))/18 992 | dyy = abs(ymax-ymin)/18 993 | ax.yaxis.set_major_formatter(yfmt) 994 | ax.set_xlim(min(xvol)-dxx,max(xvol)+dxx) 995 | ax.set_ylim(ymin-dyy,ymax+dyy) 996 | 997 | ax.xaxis.set_major_locator(MaxNLocator(7)) 998 | 999 | plt.savefig('PLOT.png',orientation='portrait',format='png') 1000 | ### 1001 | 1002 | def sortvolume(s,e): 1003 | ss=[]; ee=[]; ww=[] 1004 | for i in range(len(s)): ww.append(s[i]) 1005 | ww.sort() 1006 | for i in range(len(s)): 1007 | ss.append(s[s.index(ww[i])]) 1008 | ee.append(e[s.index(ww[i])]) 1009 | return ss, ee 1010 | ### 1011 | 1012 | ''' 1013 | #####--------------------------------------------------------- 1014 | # 6- EVALUATE Mechanical properties from Cij Matrix 1015 | #####--------------------------------------------------------- 1016 | ''' 1017 | 1018 | 1019 | def mechanical_properties(): 1020 | import numpy as np 1021 | import math, scipy, os, sys 1022 | from numpy import linalg as LA 1023 | import statistics as st 1024 | import ase.io 1025 | 1026 | np.set_printoptions(precision=3) 1027 | CRED = '\033[91m';CEND = '\033[0m' 1028 | CYEL = '\033[33m'; CEND = '\033[0m' 1029 | CPIN = '\033[46m'; 1030 | # Elastic constants have been obtained from SOEC approach mentioned in the above 1031 | # paper. For three distortions of the crystal three constants are extracted: 1032 | # C11, C44, C12. For cubic system the matrix is symmetric. 1033 | 1034 | print (CRED + "Values has to be supplied in the script::" + CEND) 1035 | 1036 | ########################## INPUT PARAMETERS assuming cubic ####################### 1037 | 1038 | c11=c22=c33=123.22 ; 1039 | c44=c55=c66=47 1040 | B = 120 1041 | #c12=c21=c13=c31=c23=c32=(1/6) * (9 * B - 3 * c11) 1042 | c12=c21=c13=c31=c23=c32=94.22 1043 | c14=c15=c16=c24=c25=c26=c34=c35=c36=0 1044 | c45=c46=c56=0 1045 | ################################################################################ 1046 | 1047 | print (CRED +"{:_^80s}".format("The STIFNESS MATRIX Cij is:")+ CEND) 1048 | Cij=[ [c11,c12,c13,c14,c15,c16], 1049 | [c21,c22,c23,c24,c25,c26], 1050 | [c31,c32,c33,c34,c35,c36], 1051 | [0 ,0 ,0 ,c44,c45,c46], 1052 | [0 ,0 ,0 ,0 ,c55,c56], 1053 | [0 ,0 ,0 ,0 ,0 ,c66] ] 1054 | Cij=np.matrix(Cij).reshape((6,6)) 1055 | print (Cij) 1056 | 1057 | ########------------Calculate variance and Mean of the Cij ----------- 1058 | # ONLY for C11 , C22 , C33 1059 | Cij_stat = [ Cij[0,0] , Cij[1,1] , Cij[2,2] ] 1060 | print (">>>", (Cij_stat) ) 1061 | STD = np.std(Cij_stat); Var = np.var(Cij_stat) ; Mean = np.mean(Cij_stat) 1062 | print ("{:6.3s} {:6.3s} {:6.3s}".format("C", "STD", "Var") ) 1063 | print ("{:6.3f} {:6.3f} {:6.3f}".format(Mean, STD/np.sqrt(3), Var) ) 1064 | 1065 | ######## ------------------------------------------------------------ 1066 | 1067 | evals, eigenvec = LA.eig(Cij) 1068 | print ("-"*40) 1069 | print("Eigenvalues are: ", evals>0) 1070 | print ("-"*40) 1071 | # ### Compliance tensor s_{ij}$ $(GPa^{-1})$ 1072 | # s_{ij} = C_{ij}^{-1}$ 1073 | 1074 | print (CRED +"{:_^80s}".format("The COMPLIANCE MATRIX Sij is:")+ CEND) 1075 | Sij = np.linalg.inv(Cij) 1076 | 1077 | print ("{} ".format(Sij)) 1078 | print ("-"*80) 1079 | 1080 | ######## -----------------------------VOIGT------------------------------- 1081 | 1082 | '''Voigt bulk modulus (GPa)''' 1083 | 1084 | #9K_v = (C_{11}+C_{22}+C_{33}) + 2(C_{12} + C_{23} + C_{31}) 1085 | Bv = ((Cij[0,0] + Cij[1,1] + Cij[2,2]) + 2 * (Cij[0,1] + Cij[1,2] + Cij[2,0])) / 9.0 1086 | 1087 | '''Voigt shear modulus (GPa)''' 1088 | 1089 | #15*G_v = (C_{11}+C_{22}+C_{33}) - (C_{12} + C_{23} + C_{31}) + 3(C_{44} + C_{55} + C_{66})$ 1090 | Gv = ((Cij[0,0] + Cij[1,1] + Cij[2,2]) - (Cij[0,1] + Cij[1,2] + Cij[2,0]) 1091 | + 3 * (Cij[3,3] + Cij[4,4] + Cij[5,5]))/15.0 1092 | 1093 | ## Young's: Voigt 1094 | Ev = (9*Bv*Gv)/(3*Bv + Gv) 1095 | 1096 | ## Poisson's ratio: Voigt 1097 | NuV = (3*Bv - Ev)/(6*Bv) 1098 | 1099 | ######## -----------------------------REUSS------------------------------- 1100 | 1101 | # Reuss bulk modulus K_R $(GPa)$ 1102 | # 1/K_R = (s_{11}+s_{22}+s_{33}) + 2(s_{12} + s_{23} + s_{31})$ 1103 | Br = 1/((Sij[0,0] + Sij[1,1] + Sij[2,2]) + 2*(Sij[0,1] + Sij[1,2] + Sij[2,0])) 1104 | 1105 | # Reuss shear modulus G_v $(GPa)$ 1106 | # 15/G_R = 4*(s_{11}+s_{22}+s_{33}) - 4*(s_{12} + s_{23} + s_{31}) + 3(s_{44} + s_{55} + s_{66})$ 1107 | Gr = (4 * (Sij[0,0] + Sij[1,1] + Sij[2,2]) - 4*(Sij[0,1] + Sij[1,2] + Sij[2,0]) 1108 | + 3 * (Sij[3,3] + Sij[4,4] + Sij[5,5])) 1109 | Gr = 15.0/Gr 1110 | 1111 | ## Young's: Reuss 1112 | Er = (9*Br*Gr)/(3*Br + Gr) 1113 | 1114 | ## Poisson's ratio: Reuss 1115 | NuR = (3*Br - Er)/(6*Br) 1116 | 1117 | ########################################################################## 1118 | 1119 | ######## -----------------------------Averages------------------------------- 1120 | 1121 | # #Hill bulk modulus K_{VRH}$ $(GPa)$ 1122 | # K_{VRH} = (K_R + K_v)/2 1123 | B_H = (Bv + Br)/2 1124 | #print ("VRH bulk modulus (GPa): %20.8f " %(B_H) ) 1125 | 1126 | # Hill shear modulus G_{VRH}$ $(GPa)$ 1127 | # G_{VRH} = (G_R + G_v)/2 1128 | G_H = (Gv + Gr)/2 1129 | #print ("VRH shear modulus (GPa): %20.8f " %(G_H) ) 1130 | 1131 | # Young modulus E = 9BG/(3B+G) 1132 | #E_H = (9 * B_H * G_H) / (3 * B_H + G_H) 1133 | E_H = (Ev + Er)/2 1134 | #print ("Young modulus E : {:1.8s} {:20.8f}".format(" ",E_H) ) 1135 | 1136 | # ### Isotropic Poisson ratio $\mu 1137 | # $\mu = (3K_{VRH} - 2G_{VRH})/(6K_{VRH} + 2G_{VRH})$ 1138 | #nu_H = (3 * B_H - 2 * G_H) / (6 * B_H + 2 * G_H ) 1139 | nu_H = (NuV + NuR) / 2 1140 | #print ("Isotropic Poisson ratio: {:15.8f} ".format(nu_H) ) 1141 | 1142 | ## Elastic Anisotropy 1143 | ## Zener anisotropy for cubic crystals only 1144 | A = 2*(c44)/(c11-c12) 1145 | 1146 | # Universal Elastic Anisotropy AU 1147 | AU = (Bv/Br) + 5*(Gv/Gr) - 6.0 1148 | 1149 | # C' tetragonal shear modulus 1150 | C = (c11-c12)/2 1151 | 1152 | ratio_V = Bv/Gv 1153 | ratio_R = Br/Gr 1154 | 1155 | print ("{:30.8s} {:20.8s} {:20.8s} {:20.8s}".format(" ","Voigt", "Reuss ", "Hill") ) 1156 | print ("{:_^80}".format("GPa")) 1157 | print ("{:16.20s} {:20.3f} {:20.3f} {:20.3f}".format("Bulk Modulus",Bv, Br, B_H) ) 1158 | print ("{:16.20s} {:20.3f} {:20.3f} {:20.3f}".format("Shear Modulus",Gv, Gr, G_H) ) 1159 | print ("{:16.20s} {:20.3f} {:20.3f} {:20.3f}".format("Young Modulus",Ev, Er, E_H) ) 1160 | print ("{:16.20s} {:20.3f} {:20.3f} {:20.3f}".format("Poisson ratio ", NuV, NuR, nu_H) ) 1161 | print ("{:16.20s} {:20.3f} {:20.3f} {:20.3f}({:5.3f})".format("B/G ratio ",Bv/Gv,Br/Gr, B_H/G_H, G_H/B_H) ) 1162 | print ("{:16.20s} {:20.3s} {:20.3s} {:20.3f}".format("Avr ratio ",'','', (Gv-Gr)/(Gv+Gr)) ) 1163 | print ("{:16.20s} {:20.3s} {:20.3s} {:20.3f}".format("Zener ratio ",'','', A) ) 1164 | print ("{:16.20s} {:20.3s} {:20.3s} {:20.3f}".format("AU ",'','', AU) ) 1165 | print ("{:16.20s} {:20.3s} {:20.3s} {:20.3f}".format("Cauchy pressure ",'','', (c12-c44)) ) 1166 | print ("{:16.20s} {:20.3s} {:20.3s} {:20.3f}".format("C'tetra Shear ",'','', C) ) 1167 | 1168 | print ("-"*80) 1169 | return Sij 1170 | ### 1171 | 1172 | 1173 | ''' 1174 | #####--------------------------------------------------------- 1175 | # INTRODUCTION 1176 | #####--------------------------------------------------------- 1177 | ''' 1178 | 1179 | #### 1180 | def Introduction(): 1181 | 1182 | print(colored('@'*80,'yellow'), end = '\n', flush=True) 1183 | print("Credit : Asif Iqbal BHATTI") 1184 | print("USAGE : Extract essential properties from VASP outputfiles.") 1185 | print("VERSION : python3 or above ") 1186 | print("FORMAT : POSCAR VASP5 format ") 1187 | print("DATE : 28/12/2019 ") 1188 | print('USAGE : execute by typing python3 sys.argv[0]') 1189 | print("VERSION : 4.0 ") 1190 | print(colored('@'*80,'yellow'), end = '\n', flush=True) 1191 | print(" ____| Python script to process various properties |____") 1192 | 1193 | ''' 1194 | #####--------------------------------------------------------- 1195 | # MAIN ENGINE 1196 | #####--------------------------------------------------------- 1197 | ''' 1198 | 1199 | #### 1200 | if __name__ == "__main__": 1201 | 1202 | Introduction() 1203 | 1204 | print("Number of processors Detected: ", mp.cpu_count()) 1205 | print(Back.MAGENTA + ' NB: POSCAR should be in VASP 5 format & without selective dynamics', end = '\n', flush=True) 1206 | print(Style.RESET_ALL) 1207 | print(colored('~'*80,'red'), end = '\n', flush=True) 1208 | print("**** Following are the options: ") 1209 | print(colored('-'*80,'red'), end = '\n', flush=True) 1210 | 1211 | print("(01) To execute only POSCAR file (local lattice distortion DEF 1-3)") 1212 | print("(02) To execute POSCAR CELL VOLUME DIFFERENCE with final CONTCAR file") 1213 | print("(03) To extract ENERGY from directories") 1214 | print("(04) To extract ELASTIC CONSTANTS from OUTCAR file (IBRION=6,ISIF=3)") 1215 | print("(05) To Fit energy vs volume curve to extract Elastic Moduli: B0 ... ") 1216 | print("(06) CONVERT POSCAR file from VASP4 to VASP5 format") 1217 | print("(07) Calculate manually Elastic properties by entering Cij values (Energy-vs-Strain)") 1218 | print("(08) Calculate lattice distortion of the structure") 1219 | print("(09) Create directories for PHONON calculations generated with PHONOPY code") 1220 | 1221 | print (colored('~'*80,'red'), end = '\n', flush=True) 1222 | 1223 | option = input("Enter the option as listed above: ") 1224 | option = int(option) 1225 | 1226 | if (option == 1): 1227 | poscar() 1228 | 1229 | elif (option == 2): 1230 | VOL_P = main_poscar() 1231 | VOL_C = main_contcar() 1232 | volume_diff(VOL_P, VOL_C) 1233 | 1234 | elif (option == 3): 1235 | create_energy_vs_volume() 1236 | 1237 | elif (option == 4): 1238 | print("OUTCAR should be in the same directory from which this script is run ") 1239 | pool = mp.Pool(mp.cpu_count()) 1240 | elastic_matrix_VASP_STRESS() 1241 | pool.close() 1242 | 1243 | elif (option == 5): 1244 | fitting_energy_vs_volume_curve_ELASTIC() 1245 | 1246 | elif (option == 6): 1247 | poscar_VASP42VASP5() 1248 | 1249 | elif (option == 7): 1250 | mechanical_properties() 1251 | 1252 | elif (option == 8): 1253 | #lattic_distortion.local_lattice_distortion(a,b,c) 1254 | lattic_distortion.local_lattice_distortion_DEF1() 1255 | #lattic_distortion.local_lattice_distortion_DEF2() 1256 | 1257 | elif (option == 9): 1258 | pass 1259 | 1260 | else: 1261 | print ("INVALID OPTION") 1262 | 1263 | 1264 | 1265 | 1266 | 1267 | 1268 | -------------------------------------------------------------------------------- /src/Main_file.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | ''' 4 | #####--------------------------------------------------------- 5 | #####--------------------------------------------------------- 6 | # Credit : Asif Iqbal BHATTI 7 | # CODE to: convert Cell Matrix to Cell Parameters 8 | # VERSION: This script runs with python3 or later 9 | # FORMAT : POSCAR VASP5 format 10 | # DATE : 28/12/2019 11 | # USAGE : python3 sys.argv[0] 12 | #####--------------------------------------------------------- 13 | #####--------------------------------------------------------- 14 | ''' 15 | 16 | def Introduction(): 17 | global message 18 | message = " ____| Python script to process various properties |____" 19 | print(message) 20 | 21 | if __name__ == "__main__": 22 | 23 | from elastic_constants import * 24 | from energy import * 25 | from contcar_poscar import * 26 | from poscar import * 27 | from fit_energy_vs_vol import * 28 | from strain import * 29 | from create_phonon_directories import * 30 | from evaluate_manually_Elastic_constants import * 31 | 32 | from colorama import Fore, Back, Style, init 33 | from termcolor import colored 34 | from pylab import * 35 | import multiprocessing as mp 36 | import compileall 37 | 38 | print ("This may take a while!") 39 | compileall.compile_dir(".", force=1) 40 | 41 | Introduction() 42 | init(autoreset=True) 43 | print(colored('@'*80,'red'), end = '\n', flush=True) 44 | print("Number of processors Detected: ", mp.cpu_count()) 45 | print(Back.MAGENTA + ' NB: POSCAR should be in VASP 5 format & without selective dynamics', end = '\n', flush=True) 46 | print(Style.RESET_ALL) 47 | print(colored('-'*80,'red'), end = '\n', flush=True) 48 | print('>>> USAGE: execute by typing python3 sys.argv[0]') 49 | print(colored('~'*80,'red'), end = '\n', flush=True) 50 | print("**** Following are the options: ") 51 | print(colored('-'*80,'red'), end = '\n', flush=True) 52 | 53 | print("(01) To execute only POSCAR file (Convert Lattice Matrix to Lattice parameter)") 54 | print("(02) To execute POSCAR CELL VOLUME DIFFERENCE with final CONTCAR file") 55 | print("(03) To extract ENERGY from directories") 56 | print("(04) To extract ELASTIC CONSTANTS from OUTCAR file (IBRION=6,ISIF=3)") 57 | print("(05) To Fit energy vs volume curve to extract Elastic Moduli: B0") 58 | print("(06) CONVERT POSCAR file from VASP4 to VASP5 format") 59 | print("(07) Extract 'ELASTIC' constants (Cij) by deforming a crystal") 60 | print("(08) Create directories for PHONON calculations generated by PHONOPY code") 61 | print("(09) Calculate manually Elastic constants by inputting Cij values") 62 | print("(10) Calculate local lattice distortion for High Entropy Alloys: DEF1") 63 | print("(11) Calculate local lattice distortion for High Entropy Alloys: DEF2") 64 | 65 | print (colored('~'*80,'red'), end = '\n', flush=True) 66 | print (colored('*'*80,'red'), end = '\n', flush=True) 67 | 68 | while True: 69 | option = input("Enter the option as listed above: ") 70 | option = int(option) 71 | 72 | if (option == 1): 73 | poscar() 74 | 75 | elif (option == 2): 76 | VOL_P = main_poscar() 77 | VOL_C = main_contcar() 78 | volume_diff(VOL_P, VOL_C) 79 | 80 | elif (option == 3): 81 | energy_vs_volume() 82 | 83 | elif (option == 4): 84 | print("OUTCAR should be in the same directory from which this script is run ") 85 | pool = mp.Pool(mp.cpu_count()) 86 | elastic_matrix_VASP_STRESS() 87 | pool.close() 88 | 89 | elif (option == 5): 90 | fitting_energy_vs_volume_curve() 91 | 92 | elif (option == 6): 93 | poscar_VASP42VASP5() 94 | 95 | elif (option == 7): 96 | Elastic_strain() 97 | 98 | elif (option == 8): 99 | create_phonon_directories() 100 | 101 | elif (option == 9): 102 | mechanical_properties() 103 | 104 | elif (option == 10): 105 | local_lattice_distortion_DEF1() 106 | 107 | elif (option == 11): 108 | local_lattice_distortion_DEF2() 109 | 110 | else: 111 | print ("INVALID OPTION") 112 | 113 | 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /src/contcar_poscar.py: -------------------------------------------------------------------------------- 1 | import os, sys, spglib 2 | import math, glob 3 | import numpy as np 4 | import subprocess 5 | from os import listdir 6 | from os.path import isfile, join 7 | from pathlib import Path 8 | from colorama import Fore, Back, Style, init 9 | 10 | ang2atomic = 1.889725988579 # 1 A = 1.889725988579 [a.u] 11 | ang2bohr = 6.7483330371 # 1 A^3 = 6.7483330371 [a.u]^3 12 | 13 | def main_poscar(): 14 | 15 | count = 0 16 | os.system("rm out_POSCARS.dat") 17 | VOL_P = []; pos = []; kk = []; lattice = []; 18 | mypath = os.getcwd() 19 | print ("-"*100) 20 | print (Back.YELLOW + "{:15s} {:15s} {:15.6s} {:15.6s} {:15.6s} {:15.15s}".format("Directory", "# of atoms", "||a||", \ 21 | "||b||", "||c||", "VOL_POS[A^3]"),end="\n" ) 22 | print ("-"*100) 23 | 24 | for entry in os.listdir(mypath): 25 | if os.path.isdir(os.path.join(mypath, entry)): 26 | #print (entry) 27 | for file in os.listdir(entry): 28 | if file == "POSCAR": 29 | count+=1; sum = 0 30 | filepath = os.path.join(entry, file) 31 | #f = open(filepath, 'r') 32 | #print (f.read()) 33 | #f.close() 34 | fo = open(filepath, 'r') 35 | ofile=open('out_POSCARS.dat','a') 36 | 37 | #print (colored('>>>>>>>> Name of the file: ','red'), fo.name, end = '\n', flush=True) 38 | 39 | ofile.write (fo.name + '\n') 40 | ofile.write ("") 41 | firstline = fo.readline() 42 | secondfline = fo.readline() 43 | Latvec1 = fo.readline() 44 | #print ("Lattice vector 1:", (Latvec1), end = '') 45 | #ofile.write (Latvec1) 46 | Latvec2 = fo.readline() 47 | #print ("Lattice vector 2:", (Latvec2), end = '') 48 | #ofile.write (Latvec2) 49 | Latvec3 = fo.readline() 50 | #print ("Lattice vector 3:", (Latvec3), end = '') 51 | #ofile.write (Latvec3) 52 | elementtype=fo.readline() 53 | elementtype = elementtype.split() 54 | #print ("Types of elements:", str(elementtype), end = '') 55 | #ofile.write (str(elementtype)) 56 | numberofatoms=fo.readline() 57 | #print ("Number of atoms:", (numberofatoms), end = '') 58 | #ofile.write ((numberofatoms)) 59 | Coordtype=fo.readline() 60 | 61 | ##########################--------------------------------------------------------- 62 | #print ("**********-------------------# of Atoms--------------------") 63 | 64 | nat = numberofatoms.split() 65 | nat = [int(i) for i in nat] 66 | for i in nat: 67 | sum = sum + i 68 | numberofatoms = sum 69 | #print ("{} :: Number of atoms: {}".format(nat, numberofatoms) ) 70 | ##########################--------------------------------------------------------- 71 | #print ("-----------------------Atomic positions-----------------") 72 | #print ("Coordtype:", (Coordtype), end = '') 73 | for x in range(int(numberofatoms)): 74 | coord = fo.readline().split() 75 | coord = [float(i) for i in coord] 76 | pos = pos + [coord] 77 | pos = np.array(pos) 78 | #print (pos) 79 | 80 | ofile.write ("\n") 81 | fo.close() 82 | ##########################--------------------------------------------------------- 83 | 84 | a=[]; b=[]; c=[]; 85 | Latvec1=Latvec1.split() 86 | Latvec2=Latvec2.split() 87 | Latvec3=Latvec3.split() 88 | 89 | ##########################--------------------------------------------------------- 90 | for ai in Latvec1: a.append(float(ai)) 91 | for bi in Latvec2: b.append(float(bi)) 92 | for ci in Latvec3: c.append(float(ci)) 93 | #print ('a=', a) 94 | ofile.write ("'a=' {}\n".format(a)) 95 | #print ('b=', b) 96 | ofile.write ("'b=' {}\n".format(b)) 97 | #print ('c=', c) 98 | ofile.write ("'c=' {}\n".format(c)) 99 | lld = local_lattice_distortion(a,b,c) 100 | ##########################--------------------------------------------------------- 101 | 102 | alpha, beta, gamma = lattice_angles(a,b,c) 103 | VOL_POS = np.dot(a, np.cross(b,c)) 104 | VOL_P.append(VOL_POS) 105 | 106 | ofile.write ("'\u03B1=' {} '\u03B2=' {} '\u03B3=' {}\n".format(alpha,beta,gamma)) 107 | ofile.write ("'||a||=' {}\n".format(np.linalg.norm(a))) 108 | ofile.write ("'||b||=' {}\n".format(np.linalg.norm(b))) 109 | ofile.write ("'||c||=' {}\n".format(np.linalg.norm(c))) 110 | #print ("#####------------------------------------------------") 111 | 112 | #print ("a={} \t ||a||={:10.6f}".format(a, np.linalg.norm(a)) ) 113 | #print ("b={} \t ||b||={:10.6f}".format(b, np.linalg.norm(b)) ) 114 | #print ("c={} \t ||c||={:10.6f}".format(c, np.linalg.norm(c)) ) 115 | print ("{:15s} {:6d} {:15.6f} {:15.6f} {:15.6f} {:15.6f}".format(fo.name, numberofatoms, np.linalg.norm(a), \ 116 | np.linalg.norm(b), np.linalg.norm(c), VOL_POS) ) 117 | 118 | print ("'\u03B1=' {:6.6f} '\u03B2=' {:6.6f} '\u03B3=' {:6.6f} g={:6.6f}".format(alpha,beta,gamma,lld)) 119 | print ("."*5) 120 | #print ('Vol= {:6.6f} A^3'.format(VOL_POS)) 121 | ofile.write ("***************************************************\n") 122 | ofile.close() 123 | print ("_"*30) 124 | print ("Number of folders detected: ", count) 125 | return VOL_P 126 | 127 | #### 128 | def main_contcar(): 129 | count = 0 130 | os.system("rm out_CONTCARS.dat") 131 | VOL_C = []; pos = []; kk = []; lattice = []; sum = 0 132 | mypath = os.getcwd() 133 | print ("-"*100) 134 | print (Back.GREEN + "{:15s} {:15s} {:15.6s} {:15.6s} {:15.6s} {:15.15s}".format("Directory", "# of atoms", "||a||", \ 135 | "||b||", "||c||", "VOL_CON[A^3]"),end="\n" ) 136 | print ("-"*100) 137 | print(Style.RESET_ALL) 138 | for entry in os.listdir(mypath): 139 | if os.path.isdir(os.path.join(mypath, entry)): 140 | for file in os.listdir(entry): 141 | 142 | if file == "CONTCAR": 143 | count+=1; sum = 0 144 | filepath = os.path.join(entry, file) 145 | fo = open(filepath, 'r') 146 | 147 | ofile=open('out_CONTCARS.dat','a') 148 | 149 | #print (colored('>>>>>>>> Name of the file: ','yellow'), fo.name, end = '\n', flush=True) 150 | ofile.write (fo.name + '\n') 151 | ofile.write ("") 152 | firstline = fo.readline() 153 | secondfline = fo.readline() 154 | Latvec1 = fo.readline() 155 | Latvec2 = fo.readline() 156 | Latvec3 = fo.readline() 157 | elementtype=fo.readline() 158 | elementtype = elementtype.split() 159 | numberofatoms=fo.readline() 160 | Coordtype=fo.readline() 161 | #print ("Coordtype:", (Coordtype), end = '') 162 | ##########################--------------------------------------------------------- 163 | #print ("**********-------------------# of Atoms--------------------") 164 | 165 | nat = numberofatoms.split() 166 | nat = [int(i) for i in nat] 167 | for i in nat: 168 | sum = sum + i 169 | numberofatoms = sum 170 | #print ("{} :: Number of atoms: {}".format(nat, numberofatoms) ) 171 | ##########################--------------------------------------------------------- 172 | #print ("//////---------------Atomic positions-----------------") 173 | for x in range(int(numberofatoms)): 174 | coord = fo.readline().split() 175 | coord = [float(i) for i in coord] 176 | pos = pos + [coord] 177 | pos = np.array(pos) 178 | #print (pos) 179 | 180 | ofile.write ("\n") 181 | fo.close() 182 | ##########################--------------------------------------------------------- 183 | a=[]; b=[]; c=[]; 184 | Latvec1=Latvec1.split() 185 | Latvec2=Latvec2.split() 186 | Latvec3=Latvec3.split() 187 | ##########################--------------------------------------------------------- 188 | for ai in Latvec1: a.append(float(ai)) 189 | for bi in Latvec2: b.append(float(bi)) 190 | for ci in Latvec3: c.append(float(ci)) 191 | #print ('a=', a) 192 | ofile.write ("'a=' {}\n".format(a)) 193 | #print ('b=', b) 194 | ofile.write ("'b=' {}\n".format(b)) 195 | #print ('c=', c) 196 | ofile.write ("'c=' {}\n".format(c)) 197 | lld = local_lattice_distortion(a,b,c) 198 | ##########################--------------------------------------------------------- 199 | 200 | alpha, beta, gamma = lattice_angles(a,b,c) 201 | VOL_CON = np.dot(a, np.cross(b,c)) 202 | VOL_C.append(VOL_CON) 203 | 204 | ofile.write ("'\u03B1=' {} '\u03B2=' {} '\u03B3=' {}\n".format(alpha,beta,gamma)) 205 | ofile.write ("'||a||=' {}\n".format(np.linalg.norm(a))) 206 | ofile.write ("'||b||=' {}\n".format(np.linalg.norm(b))) 207 | ofile.write ("'||c||=' {}\n".format(np.linalg.norm(c))) 208 | #print ("-"*80) 209 | 210 | #print ("a={} \t ||a||={:10.6f}".format(a, np.linalg.norm(a)) ) 211 | #print ("b={} \t ||b||={:10.6f}".format(b, np.linalg.norm(b)) ) 212 | #print ("c={} \t ||c||={:10.6f}".format(c, np.linalg.norm(c)) ) 213 | print ("{:15s} {:6d} {:15.6f} {:15.6f} {:15.6f} {:15.6f}".format(fo.name, numberofatoms, np.linalg.norm(a), \ 214 | np.linalg.norm(b), np.linalg.norm(c), VOL_CON) ) 215 | 216 | print ("'\u03B1=' {:6.6f} '\u03B2=' {:6.6f} '\u03B3=' {:6.6f} g={:6.6f}".format(alpha,beta,gamma,lld)) 217 | print ("."*5) 218 | #print ('Vol= {:6.6f} A^3'.format(VOL_CON), end="\n") 219 | ofile.write ("***************************************************\n") 220 | ofile.close() 221 | #print (VOL_C) 222 | print ("-"*80) 223 | print ("Number of folders detected: ", count) 224 | return VOL_C 225 | 226 | 227 | #### math.sin function takes argument in radians ONLY 228 | def volume(a,b,c,alpha,beta,gamma): 229 | length = np.linalg.norm(a) * np.linalg.norm(b) * np.linalg.norm(c) 230 | volume = length * ( np.sqrt(1 + 2 * math.cos(alpha) * math.cos(beta) * math.cos(gamma) - math.cos(alpha)**2 - math.cos(beta)**2 - math.cos(gamma)**2) ) 231 | vol_au = volume * ang2bohr 232 | return volume, vol_au 233 | 234 | #### Ordering of angles does matter 235 | def lattice_angles(a,b,c): 236 | ### gamma = Cos-1( (a.b)/||a||.||b|| ) 237 | ### alpha = Cos-1( (b.c)/||b||.||c|| ) 238 | ### beta = Cos-1( (a.c)/||a||.||c|| ) 239 | gamma = math.degrees(math.acos(np.dot(a,b) / (np.linalg.norm(a) * np.linalg.norm(b)))) 240 | alpha = math.degrees(math.acos(np.dot(b,c) / (np.linalg.norm(b) * np.linalg.norm(c)))) 241 | beta = math.degrees(math.acos(np.dot(a,c) / (np.linalg.norm(a) * np.linalg.norm(c)))) 242 | return alpha, beta, gamma 243 | #### 244 | def volume_diff(VOL_P, VOL_C): 245 | n=os.popen("find . -mindepth 1 -maxdepth 1 -type d | wc -l").read() 246 | print ("-"*100) 247 | print ("VOL Diff A^3 %18s %12s %15.15s" %("CONTCAR", "POSCAR", "contcar-poscar")) 248 | print ("-"*100) 249 | for i in range(int(n)): 250 | print ("The difference is: %12.6f %12.6f %15.8f " %(VOL_C[i], VOL_P[i], VOL_C[i] - VOL_P[i]) ) 251 | 252 | -------------------------------------------------------------------------------- /src/create_phonon_directories.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | #_____________________________________________________________________________ 3 | ''' 4 | USAGE: python3 script to create directories from POSCAR files generated from 5 | PHONOPY code. 6 | Credit: Asif Iqbal Bhatti 7 | DATED: 19-01-2020 8 | 9 | ''' 10 | #_____________________________________________________________________________ 11 | import os, sys, scipy 12 | import pathlib, subprocess, shutil 13 | from os import listdir 14 | from os.path import isfile, join 15 | import os.path 16 | import multiprocessing as mp 17 | import fnmatch 18 | import time 19 | 20 | #_____________________________________________________________________________ 21 | os.system('rm -r disp-*') 22 | #os.system('phonopy -d --dim="2 2 2"') ## It will call a phonopy code 23 | #subprocess.call(['phonopy','-v', '-d', '--dim=3 3 3'],shell = False) ## It will call a phonopy code 24 | #_____________________________________________________________________________ 25 | 26 | 27 | def copy_fntn(k): 28 | for i in range(1, int(k)+1): 29 | shutil.rmtree('disp-'+str(i).zfill(3), ignore_errors=True) #overwrite a directory 30 | os.mkdir('disp-'+str(i).zfill(3)) 31 | #subprocess.check_call(['mkdir', 'disp-'+str(i).zfill(3)]) 32 | #subprocess.check_call('cd disp-'+str(i).zfill(3), shell=True) 33 | # print(str(i).zfill(3)) 34 | # 35 | # The zfill()/rjust() is a function associated with the string object. 36 | # 3 is the expected length of the string after padding. 37 | # 38 | os.system('cp INCAR disp-'+str(i).zfill(3) ) 39 | os.system('cp POTCAR disp-'+str(i).zfill(3) ) 40 | os.system('cp KPOINTS disp-'+str(i).zfill(3) ) 41 | #os.system('cp job.sh disp-'+str(i).zfill(3) ) 42 | #os.system('cp WAVECAR disp-'+str(i).zfill(3) ) 43 | subprocess.call(['cp','-r','POSCAR-'+str(i).zfill(3),'disp-'+str(i).zfill(3)], shell = False) 44 | os.chdir('disp-'+str(i).zfill(3)) 45 | shutil.copyfile("POSCAR-"+str(i).zfill(3), "POSCAR") 46 | #os.system('ls') 47 | os.chdir('../') 48 | 49 | 50 | def create_phonon_directories(): 51 | print("Number of processors Detected: ", mp.cpu_count()) 52 | pool = mp.Pool(4) 53 | print("*"*80) 54 | if not os.path.exists('POSCAR'): 55 | print (' ERROR: POSCAR does not exist here.') 56 | sys.exit(0) 57 | else: 58 | counter=0 59 | mypath = os.getcwd() 60 | for entry in os.listdir(mypath): 61 | if os.path.isfile(os.path.join(mypath, entry)): 62 | if fnmatch.fnmatchcase(entry,'POSCAR-*'): 63 | counter+=1 64 | print ("# of POSCAR-* files generated with Phonopy code: ----> {}".format(counter) ) 65 | print("*"*80) 66 | 67 | start_time = time.time() 68 | #copy_fntn(counter) 69 | #p = mp.Process(target=copy_fntn, args=('9',)) 70 | #p.start() 71 | #p.join() 72 | with pool as p: 73 | p.map(copy_fntn, [counter]) 74 | end_time = time.time() 75 | print("total time taken for this loop: ", end_time - start_time) 76 | 77 | if __name__ == "__main__": 78 | create_phonon_directories() 79 | 80 | 81 | -------------------------------------------------------------------------------- /src/elastic_constants.py: -------------------------------------------------------------------------------- 1 | import os, sys, spglib 2 | import math, glob 3 | import numpy as np 4 | import subprocess 5 | from os import listdir 6 | from os.path import isfile, join 7 | from pathlib import Path 8 | 9 | ang2atomic = 1.889725988579 # 1 A = 1.889725988579 [a.u] 10 | ang2bohr = 6.7483330371 # 1 A^3 = 6.7483330371 [a.u]^3 11 | 12 | class Elastic_Matrix: 13 | def print_Cij_Matrix(): ###EXERCISE 14 | Bij = []; C = "C" 15 | for i in range(0, 6, 1): 16 | Bij.append([]) 17 | for j in range(1,7, 1): 18 | Bij[i].append((C + str(i+1) + str(j))) 19 | l = np.matrix(Bij) 20 | return l 21 | 22 | def langragian_strain(): 23 | kk = ('x', 'y', 'z'); C = "E"; Eij=[] 24 | eta = { 25 | "xx" : 11, 26 | "yy" : 22, 27 | "zz" : 33, 28 | "yz" : 23, 29 | "xz" : 13, 30 | "xy" : 12 } 31 | print ( "The Langragian strain in Voigt notation: ") 32 | print ( eta.items()) 33 | 34 | for n in kk: 35 | for m in kk: 36 | Eij.append( (C + str(n) + str(m)) ) 37 | ls = np.matrix(Eij).reshape(3,3) 38 | return ls 39 | 40 | 41 | def elastic_matrix_VASP_STRESS(): 42 | while True: 43 | if not os.path.exists('OUTCAR'): 44 | print (' ERROR: OUTCAR does not exist here.') 45 | sys.exit(0) 46 | 47 | s=np.zeros((6,6)) 48 | c=np.zeros((6,6)) 49 | file = open("OUTCAR",'r') 50 | lines = file.readlines() 51 | file.close() 52 | 53 | for i in lines: 54 | if "TOTAL ELASTIC MODULI (kBar)" in i: 55 | ll=lines.index(i) 56 | if "LATTYP" in i: 57 | crystaltype=str(i.split()[3]) 58 | print ("DETECTED CRYSTAL FROM OUTCAR:", crystaltype) 59 | print (" ") 60 | for i in range(0,6): 61 | l=lines[ll+3+i] # indexing a line in huge file 62 | word = l.split() 63 | s[i][:] = word[1:7] 64 | for j in range(0,6): 65 | c[i][j] = float(s[i][j])/10.0 66 | 67 | ##########-------------------stress tensor------------------ 68 | 69 | Cij = np.matrix(c) 70 | np.set_printoptions(precision=4, suppress=True) 71 | print (Cij) 72 | print(Elastic_Matrix.print_Cij_Matrix() ) 73 | print(Elastic_Matrix.langragian_strain() ) 74 | print ("\nEigen Values of the matrix Cij:") 75 | evals = np.linalg.eigvals(Cij) 76 | if evals.all() > 0: 77 | print(evals) 78 | print("All Eigen values are positive") 79 | 80 | ##########-------------------Compliance tensor------------------ 81 | ##########------------------- s_{ij} = C_{ij}^{-1} 82 | 83 | Sij = np.linalg.inv(Cij) 84 | 85 | #---------------------------- ELASTIC PROPERTIES ----------------------------------- 86 | 87 | stability_test(Cij, crystaltype) 88 | 89 | ######## -----------------------------VOIGT------------------------------- 90 | 91 | '''Voigt bulk modulus (GPa)''' 92 | 93 | #9K_v = (C_{11}+C_{22}+C_{33}) + 2(C_{12} + C_{23} + C_{31}) 94 | Bv = ((Cij[0,0] + Cij[1,1] + Cij[2,2]) + 2 * (Cij[0,1] + Cij[1,2] + Cij[2,0])) / 9.0 95 | 96 | '''Voigt shear modulus (GPa)''' 97 | 98 | #15*G_v = (C_{11}+C_{22}+C_{33}) - (C_{12} + C_{23} + C_{31}) + 3(C_{44} + C_{55} + C_{66})$ 99 | Gv = ((Cij[0,0] + Cij[1,1] + Cij[2,2]) - (Cij[0,1] + Cij[1,2] + Cij[2,0]) 100 | + 3 * (Cij[3,3] + Cij[4,4] + Cij[5,5]))/15.0 101 | 102 | ## Young's: Voigt 103 | Ev = (9*Bv*Gv)/(3*Bv + Gv) 104 | 105 | ## Poisson's ratio: Voigt 106 | NuV = (3*Bv - Ev)/(6*Bv) 107 | 108 | ######## -----------------------------REUSS------------------------------- 109 | 110 | # Reuss bulk modulus K_R $(GPa)$ 111 | # 1/K_R = (s_{11}+s_{22}+s_{33}) + 2(s_{12} + s_{23} + s_{31})$ 112 | Br = 1/((Sij[0,0] + Sij[1,1] + Sij[2,2]) + 2*(Sij[0,1] + Sij[1,2] + Sij[2,0])) 113 | 114 | # Reuss shear modulus G_v $(GPa)$ 115 | # 15/G_R = 4*(s_{11}+s_{22}+s_{33}) - 4*(s_{12} + s_{23} + s_{31}) + 3(s_{44} + s_{55} + s_{66})$ 116 | Gr = (4 * (Sij[0,0] + Sij[1,1] + Sij[2,2]) - 4*(Sij[0,1] + Sij[1,2] + Sij[2,0]) 117 | + 3 * (Sij[3,3] + Sij[4,4] + Sij[5,5])) 118 | Gr = 15.0/Gr 119 | 120 | ## Young's: Reuss 121 | Er = (9*Br*Gr)/(3*Br + Gr) 122 | 123 | ## Poisson's ratio: Reuss 124 | NuR = (3*Br - Er)/(6*Br) 125 | 126 | ########################################################################## 127 | 128 | ######## -----------------------------Averages------------------------------- 129 | 130 | # #Hill bulk modulus K_{VRH}$ $(GPa)$ 131 | # K_{VRH} = (K_R + K_v)/2 132 | B_H = (Bv + Br)/2 133 | #print ("VRH bulk modulus (GPa): %20.8f " %(B_H) ) 134 | 135 | # Hill shear modulus G_{VRH}$ $(GPa)$ 136 | # G_{VRH} = (G_R + G_v)/2 137 | G_H = (Gv + Gr)/2 138 | #print ("VRH shear modulus (GPa): %20.8f " %(G_H) ) 139 | 140 | # Young modulus E = 9BG/(3B+G) 141 | #E_H = (9 * B_H * G_H) / (3 * B_H + G_H) 142 | E_H = (Ev + Er)/2 143 | #print ("Young modulus E : {:1.8s} {:20.8f}".format(" ",E_H) ) 144 | 145 | # ### Isotropic Poisson ratio $\mu 146 | # $\mu = (3K_{VRH} - 2G_{VRH})/(6K_{VRH} + 2G_{VRH})$ 147 | #nu_H = (3 * B_H - 2 * G_H) / (6 * B_H + 2 * G_H ) 148 | nu_H = (NuV + NuR) / 2 149 | #print ("Isotropic Poisson ratio: {:15.8f} ".format(nu_H) ) 150 | 151 | ## Elastic Anisotropy 152 | ## Zener anisotropy for cubic crystals only 153 | A = 2*(c44)/(c11-c12) 154 | 155 | # Universal Elastic Anisotropy AU 156 | AU = (Bv/Br) + 5*(Gv/Gr) - 6.0 157 | 158 | # C' tetragonal shear modulus 159 | C = (c11-c12)/2 160 | 161 | ratio_V = Bv/Gv 162 | ratio_R = Br/Gr 163 | print ("{:_^80}".format("GPa")) 164 | print ("{:25.8s} {:15.8s} {:15.8s} {:15.8s}".format(" ","Voigt", "Reuss ", "Hill") ) 165 | print ("{:16.20s} {:15.3f} {:15.3f} {:15.3f}".format("Bulk Modulus",Bv, Br, B_H) ) 166 | print ("{:16.20s} {:15.3f} {:15.3f} {:15.3f}".format("Shear Modulus",Gv, Gr, G_H) ) 167 | print ("{:16.20s} {:15.3f} {:15.3f} {:15.3f}".format("Young Modulus",Ev, Er, E_H) ) 168 | print ("{:-^80}".format("-")) 169 | print ("{:16.20s} {:15.3f} {:15.3f} {:15.3f}".format("Poisson ratio ", NuV, NuR, nu_H) ) 170 | print ("{:16.20s} {:15.3f} {:15.3f} {:15.3f}({:5.3f})".format("B/G ratio ",Bv/Gv,Br/Gr, B_H/G_H, G_H/B_H) ) 171 | print ("{:16.20s} {:15.3s} {:15.3s} {:15.3f}".format("Zener ratio Az",'','', A) ) 172 | print ("{:16.20s} {:15.3s} {:15.3s} {:15.3f}".format("Avr ratio ",'','', (Gv-Gr)/(Gv+Gr)) ) 173 | print ("{:16.20s} {:15.3s} {:15.3s} {:15.3f}".format("AU ",'','', AU) ) 174 | print ("{:16.20s} {:15.3s} {:15.3s} {:15.3f}".format("Cauchy pressure ",'','', (c12-c44)) ) 175 | print ("{:16.20s} {:15.3s} {:15.3s} {:15.3f}".format("C'tetra Shear ",'','', C) ) 176 | 177 | print ("-"*80) 178 | return Sij 179 | 180 | 181 | 182 | def ductile_test(ratio): 183 | if(ratio > 1.75): 184 | return "ductile" 185 | else: 186 | return "brittle" 187 | ### 188 | 189 | def stability_test(matrix, crystaltype): 190 | c = np.copy(matrix) 191 | 192 | if(crystaltype =="cubic"): 193 | print ("Cubic crystal system \n") 194 | print ("Born stability criteria for the stability of cubic system are : \ [Ref- Mouhat and Coudert, PRB 90, 224104 (2014)] \n") 195 | print ("(i) C11 - C12 > 0; (ii) C11 + 2C12 > 0; (iii) C44 > 0 \n ") 196 | 197 | ## check (i) keep in mind list starts with 0, so c11 is stored as c00 198 | if(c[0][0] - c[0][1] > 0.0): 199 | print ("Condition (i) satisfied.") 200 | else: 201 | print ("Condition (i) NOT satisfied.") 202 | 203 | if(c[0][0] + 2*c[0][1] > 0.0): 204 | print ("Condition (ii) satified.") 205 | else: 206 | print ("Condition (ii) NOT satisfied.") 207 | 208 | if(c[3][3] > 0.0): 209 | print ("Condition (iii) satified.") 210 | else: 211 | print ("Condition (iii) NOT satisfied.") 212 | 213 | if(crystaltype =="hexagonal"): 214 | print ("Hexagonal crystal system \n") 215 | print ("Born stability criteria for the stability of hexagonal system are \: [Ref- Mouhat and Coudert, PRB 90, 224104 (2014)] \n") 216 | print ("(i) C11 - C12 > 0; (ii) 2*C13^2 < C33(C11 + C12); (iii) C44 > 0 \n ") 217 | 218 | ## check (i) keep in mind list starts with 0, so c11 is stored as c00 219 | if(c[0][0] - c[0][1] > 0.0): 220 | print ("Condition (i) satisfied.") 221 | else: 222 | print ("Condition (i) NOT satisfied.") 223 | 224 | if(2*(c[0][2]*c[0][2]) < c[2][2]*(c[0][0] + c[0][1])): 225 | print ("Condition (ii) satified.") 226 | else: 227 | print ("Condition (ii) NOT satisfied.") 228 | 229 | if(c[3][3] > 0.0): 230 | print ("Condition (iii) satified.") 231 | else: 232 | print ("Condition (iii) NOT satisfied.") 233 | ### 234 | 235 | def born_stability_criterion(): 236 | print ("Born stability criteria for the stability of following systems \n") 237 | print ("Cubic crystal system.... \n") 238 | print ("(i) C11 - C12 > 0; (ii) C11 + 2C12 > 0; (iii) C44 > 0 \n ") 239 | print ("Hexagonal crystal system.... \n") 240 | print ("(i) C11 - C12 > 0; (ii) 2*C13^2 < C33(C11 + C12); (iii) C44 > 0 \n ") 241 | print ("Tetragonal crystal system.... \n") 242 | print ("(i) C11 - C12 > 0; (ii) 2*C13^2 < C33(C11 + C12); (iii) C44 > 0; (iv) C66 > 0; (v) 2C16^2 < C66*(C11-C12) \n ") 243 | print ("rhombohedral crystal system.... \n") 244 | print ("(i) C11 - C12 > 0; (ii) C13^2 < (1/2)*C33(C11 + C12); (iii) C14^2 < (1/2)*C44*(C11-C12) = C44*C66; (iv) C44 > 0; \n ") 245 | print ("orthorhombic crystal system.... \n") 246 | print ("(i) C11 > 0; (ii) C11*C22 > C12^2; (iii) C11*C22*C33 + 2C12*C13*C23 - C11*C23^2 - C22*C13^2 - C33*C12^2 > 0; (iv) C44 > 0; (v) C55 > 0 ; (vi) C66 > 0 \n") 247 | print ("Monoclinic crystal system.... \n") 248 | print ("[Ref- Mouhat and Coudert, PRB 90, 224104 (2014), and Wu et al. PRB 76, 054115 (2007)] \n") 249 | print ("(i) C11 > 0; (ii) C22 > 0; (iii) C33 > 0; (iv) C44 > 0; (v) C55 > 0 ; (vi) C66 > 0 ") 250 | print ("(vii) [C11 + C22 + C33 + 2*(C12 + C13 + C23)] > 0; (viii) C33*C55 - C35^2 > 0; (ix) C44*C66 - C46^2 > 0; (x) C22 + C33 - 2*C23 > 0 ") 251 | print ("(xi) C22*(C33*C55 - C35^2) + 2*C23*C25*C35 - (C23^2)*C55 - (C25^2)*C33 > 0 ") 252 | print ("(xii) 2*[C15*C25*(C33*C12 - C13*C23) + C15*C35*(C22*C13 - C12*C23) + C25*C35*(C11*C23 - C12*C13)] - [C15*C15*(C22*C33 - C23^2) + C25*C25*(C11*C33 - C13^2) + C35*C35*(C11*C22 - C12^2)] + C55*g > 0 ") 253 | print (" where, g = [C11*C22*C33 - C11*C23*C23 - C22*C13*C13 - C33*C12*C12 + 2*C12*C13*C23 ] " ) 254 | ### 255 | -------------------------------------------------------------------------------- /src/energy.py: -------------------------------------------------------------------------------- 1 | import os, sys, spglib 2 | import math, glob 3 | import numpy as np 4 | import subprocess 5 | from os import listdir 6 | from os.path import isfile, join 7 | from pathlib import Path 8 | 9 | ang2atomic = 1.889725988579 # 1 A = 1.889725988579 [a.u] 10 | Ang32Bohr3 = 6.74833304162 # 1 A^3 = 6.7483330371 [a.u]^3 11 | eV2Hartree = 0.036749309 12 | 13 | def energy_vs_volume(): 14 | import fnmatch 15 | mypath = os.getcwd() 16 | os.system("rm energy-vs-volume energy-vs-strain") 17 | eV2Hartree=0.036749309 18 | Ang32Bohr3=6.74833304162 19 | 20 | E=[]; dir_list=[]; count = 0; dir_E=[]; 21 | vol_cell=[]; strain_file=[]; strain_value=[] # strain_value is deformation 22 | 23 | print (" >>>>> Extracting Energy from directories <<<<<<") 24 | for entry in os.listdir(mypath): 25 | if not os.path.exists('strain-01'): 26 | print (' ERROR: strain-* does not exist here.') 27 | sys.exit(0) 28 | if fnmatch.fnmatchcase(entry,'strain-*'): 29 | f = open(entry,'r') 30 | lines = f.readline() #Read first line only 31 | strain_value.append( float(lines) ) 32 | f.close() 33 | if os.path.isfile(os.path.join(mypath, entry)): 34 | strain_file.append(entry) 35 | 36 | if os.path.isdir(os.path.join(mypath, entry)): 37 | dir_list.append(entry) 38 | 39 | for file in os.listdir(entry): 40 | if file == "OUTCAR": 41 | filepath = os.path.join(entry, file) 42 | if not os.path.exists(filepath): 43 | print (' ERROR: OUTCAR does not exist here.') 44 | sys.exit(0) 45 | f = open(filepath,'r') 46 | lines = f.readlines() 47 | f.close() 48 | 49 | for i in lines: 50 | if " free energy TOTEN =" in i: 51 | m=float(i.split()[4]) 52 | if " volume of cell :" in i: 53 | v=float(i.split()[4]) 54 | vol_cell.append(v) 55 | E.append(m) 56 | count+=1 57 | print("# of folders detected: ", count) 58 | print ("Directory :%10.6s %14s %18s %25.20s " % ("Folder", "Energy(eV)", "Vol_of_cell(A^3)", "strain_deformation" )) 59 | 60 | for i in range(math.floor(count/2)): # 0 to 4 61 | print ("Folder name: %10.10s %16.8f %16.8f %16.12s %14.4f" %(dir_list[i], E[i], vol_cell[i], strain_file[i], strain_value[i] )) 62 | if (bool(math.floor(count/2))): 63 | i = math.floor(count/2) 64 | print(Back.GREEN + 'Folder name: %10.10s %16.8f %16.8f %16.12s %14.4f <--Ref' % (dir_list[i], E[i], vol_cell[i], strain_file[i], strain_value[i] )) 65 | print(Style.RESET_ALL, end="") 66 | for i in range(math.ceil(count/2), count, 1): 67 | print ("Folder name: %10.10s %16.8f %16.8f %16.12s %14.4f" %(dir_list[i], E[i], vol_cell[i], strain_file[i], strain_value[i] )) 68 | #rc = subprocess.Popen(['bash', 'extract_energy.sh']) 69 | 70 | print (colored('ENERGIES & VOLUMES ARE WRITTEN IN ATOMIC UNITS TO A FILE ','yellow'), end = '\n', flush=True) 71 | print (colored('IT WILL BE READ BY ELASTIC SCRIPTS FOR POSTPROCESSING eV-->Ha; A^3-->Bohr^3','yellow'), end = '\n', flush=True) 72 | 73 | file = open("energy-vs-volume",'w') 74 | for i in range(count): 75 | file.write ("%14.6f %14.6f\n" %(vol_cell[i] * Ang32Bohr3, E[i] * eV2Hartree)) 76 | file.close() 77 | 78 | file = open("energy-vs-strain",'w') 79 | for i in range(count): 80 | file.write ("%12.6f %14.6f\n" %(strain_value[i], E[i] * eV2Hartree)) 81 | file.close() 82 | ### -------------------------------------------------------------------------------- /src/evaluate_manually_Elastic_constants.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | ''' 4 | # | Elastic Properties 5 | # | Code for calculating mechanical properties 6 | # from Energy vs Strain relationship 7 | # 8 | # Equations can be found at Golesorkhtabar, R., Pavone, P., Spitaler, J., 9 | # Puschnig, P. & Draxl, C. ElaStic: A tool for calculating second-order elastic 10 | # constants from first principles. Comput. Phys. Commun. 184, 1861–1873 (2013). 11 | OR http://wolf.ifj.edu.pl/elastic/index.html 12 | https://www.materialsproject.org/wiki/index.php/Elasticity_calculations 13 | ''' 14 | 15 | import numpy as np 16 | import math, scipy, os, sys 17 | from numpy import linalg as LA 18 | import statistics as st 19 | import ase.io 20 | 21 | np.set_printoptions(precision=3) 22 | CRED = '\033[91m';CEND = '\033[0m' 23 | CYEL = '\033[33m'; CEND = '\033[0m' 24 | CPIN = '\033[46m'; 25 | 26 | def mechanical_properties(): 27 | # Elastic constants have been obtained from SOEC approach mentioned in the above 28 | # paper. For three distortions of the crystal three constants are extracted: 29 | # C11, C44, C12. For cubic system the matrix is symmetric. 30 | 31 | print (CRED + "Values has to be supplied in the script::" + CEND) 32 | 33 | ########################## INPUT PARAMETERS assuming cubic ####################### 34 | 35 | c11=c22=c33=123.22 ; 36 | c44=c55=c66=47 37 | B = 120 38 | #c12=c21=c13=c31=c23=c32=(1/6) * (9 * B - 3 * c11) 39 | c12=c21=c13=c31=c23=c32=94.22 40 | c14=c15=c16=c24=c25=c26=c34=c35=c36=0 41 | c45=c46=c56=0 42 | ################################################################################ 43 | 44 | print (CRED +"{:_^80s}".format("The STIFNESS MATRIX Cij is:")+ CEND) 45 | Cij=[ [c11,c12,c13,c14,c15,c16], 46 | [c21,c22,c23,c24,c25,c26], 47 | [c31,c32,c33,c34,c35,c36], 48 | [0 ,0 ,0 ,c44,c45,c46], 49 | [0 ,0 ,0 ,0 ,c55,c56], 50 | [0 ,0 ,0 ,0 ,0 ,c66] ] 51 | Cij=np.matrix(Cij).reshape((6,6)) 52 | print (Cij) 53 | 54 | ########------------Calculate variance and Mean of the Cij ----------- 55 | # ONLY for C11 , C22 , C33 56 | Cij_stat = [ Cij[0,0] , Cij[1,1] , Cij[2,2] ] 57 | print (">>>", (Cij_stat) ) 58 | STD = np.std(Cij_stat); Var = np.var(Cij_stat) ; Mean = np.mean(Cij_stat) 59 | print ("{:6.3s} {:6.3s} {:6.3s}".format("C", "STD", "Var") ) 60 | print ("{:6.3f} {:6.3f} {:6.3f}".format(Mean, STD/np.sqrt(3), Var) ) 61 | 62 | ######## ------------------------------------------------------------ 63 | 64 | evals, eigenvec = LA.eig(Cij) 65 | print ("-"*40) 66 | print("Eigenvalues are: ", evals>0) 67 | print ("-"*40) 68 | # ### Compliance tensor s_{ij}$ $(GPa^{-1})$ 69 | # s_{ij} = C_{ij}^{-1}$ 70 | 71 | print (CRED +"{:_^80s}".format("The COMPLIANCE MATRIX Sij is:")+ CEND) 72 | Sij = np.linalg.inv(Cij) 73 | 74 | print ("{} ".format(Sij)) 75 | print ("-"*80) 76 | 77 | ######## -----------------------------VOIGT------------------------------- 78 | 79 | '''Voigt bulk modulus (GPa)''' 80 | 81 | #9K_v = (C_{11}+C_{22}+C_{33}) + 2(C_{12} + C_{23} + C_{31}) 82 | Bv = ((Cij[0,0] + Cij[1,1] + Cij[2,2]) + 2 * (Cij[0,1] + Cij[1,2] + Cij[2,0])) / 9.0 83 | 84 | '''Voigt shear modulus (GPa)''' 85 | 86 | #15*G_v = (C_{11}+C_{22}+C_{33}) - (C_{12} + C_{23} + C_{31}) + 3(C_{44} + C_{55} + C_{66})$ 87 | Gv = ((Cij[0,0] + Cij[1,1] + Cij[2,2]) - (Cij[0,1] + Cij[1,2] + Cij[2,0]) 88 | + 3 * (Cij[3,3] + Cij[4,4] + Cij[5,5]))/15.0 89 | 90 | ## Young's: Voigt 91 | Ev = (9*Bv*Gv)/(3*Bv + Gv) 92 | 93 | ## Poisson's ratio: Voigt 94 | NuV = (3*Bv - Ev)/(6*Bv) 95 | 96 | ######## -----------------------------REUSS------------------------------- 97 | 98 | # Reuss bulk modulus K_R $(GPa)$ 99 | # 1/K_R = (s_{11}+s_{22}+s_{33}) + 2(s_{12} + s_{23} + s_{31})$ 100 | Br = 1/((Sij[0,0] + Sij[1,1] + Sij[2,2]) + 2*(Sij[0,1] + Sij[1,2] + Sij[2,0])) 101 | 102 | # Reuss shear modulus G_v $(GPa)$ 103 | # 15/G_R = 4*(s_{11}+s_{22}+s_{33}) - 4*(s_{12} + s_{23} + s_{31}) + 3(s_{44} + s_{55} + s_{66})$ 104 | Gr = (4 * (Sij[0,0] + Sij[1,1] + Sij[2,2]) - 4*(Sij[0,1] + Sij[1,2] + Sij[2,0]) 105 | + 3 * (Sij[3,3] + Sij[4,4] + Sij[5,5])) 106 | Gr = 15.0/Gr 107 | 108 | ## Young's: Reuss 109 | Er = (9*Br*Gr)/(3*Br + Gr) 110 | 111 | ## Poisson's ratio: Reuss 112 | NuR = (3*Br - Er)/(6*Br) 113 | 114 | ########################################################################## 115 | 116 | ######## -----------------------------Averages------------------------------- 117 | 118 | # #Hill bulk modulus K_{VRH}$ $(GPa)$ 119 | # K_{VRH} = (K_R + K_v)/2 120 | B_H = (Bv + Br)/2 121 | #print ("VRH bulk modulus (GPa): %20.8f " %(B_H) ) 122 | 123 | # Hill shear modulus G_{VRH}$ $(GPa)$ 124 | # G_{VRH} = (G_R + G_v)/2 125 | G_H = (Gv + Gr)/2 126 | #print ("VRH shear modulus (GPa): %20.8f " %(G_H) ) 127 | 128 | # Young modulus E = 9BG/(3B+G) 129 | #E_H = (9 * B_H * G_H) / (3 * B_H + G_H) 130 | E_H = (Ev + Er)/2 131 | #print ("Young modulus E : {:1.8s} {:20.8f}".format(" ",E_H) ) 132 | 133 | # ### Isotropic Poisson ratio $\mu 134 | # $\mu = (3K_{VRH} - 2G_{VRH})/(6K_{VRH} + 2G_{VRH})$ 135 | #nu_H = (3 * B_H - 2 * G_H) / (6 * B_H + 2 * G_H ) 136 | nu_H = (NuV + NuR) / 2 137 | #print ("Isotropic Poisson ratio: {:15.8f} ".format(nu_H) ) 138 | 139 | ## Elastic Anisotropy 140 | ## Zener anisotropy for cubic crystals only 141 | A = 2*(c44)/(c11-c12) 142 | 143 | # Universal Elastic Anisotropy AU 144 | AU = (Bv/Br) + 5*(Gv/Gr) - 6.0 145 | 146 | # C' tetragonal shear modulus 147 | C = (c11-c12)/2 148 | 149 | ratio_V = Bv/Gv 150 | ratio_R = Br/Gr 151 | 152 | print ("{:30.8s} {:20.8s} {:20.8s} {:20.8s}".format(" ","Voigt", "Reuss ", "Hill") ) 153 | print ("{:_^80}".format("GPa")) 154 | print ("{:16.20s} {:20.3f} {:20.3f} {:20.3f}".format("Bulk Modulus",Bv, Br, B_H) ) 155 | print ("{:16.20s} {:20.3f} {:20.3f} {:20.3f}".format("Shear Modulus",Gv, Gr, G_H) ) 156 | print ("{:16.20s} {:20.3f} {:20.3f} {:20.3f}".format("Young Modulus",Ev, Er, E_H) ) 157 | print ("{:16.20s} {:20.3f} {:20.3f} {:20.3f}".format("Poisson ratio ", NuV, NuR, nu_H) ) 158 | print ("{:16.20s} {:20.3f} {:20.3f} {:20.3f}({:5.3f})".format("B/G ratio ",Bv/Gv,Br/Gr, B_H/G_H, G_H/B_H) ) 159 | print ("{:16.20s} {:20.3s} {:20.3s} {:20.3f}".format("Avr ratio ",'','', (Gv-Gr)/(Gv+Gr)) ) 160 | print ("{:16.20s} {:20.3s} {:20.3s} {:20.3f}".format("Zener ratio ",'','', A) ) 161 | print ("{:16.20s} {:20.3s} {:20.3s} {:20.3f}".format("AU ",'','', AU) ) 162 | print ("{:16.20s} {:20.3s} {:20.3s} {:20.3f}".format("Cauchy pressure ",'','', (c12-c44)) ) 163 | print ("{:16.20s} {:20.3s} {:20.3s} {:20.3f}".format("C'tetra Shear ",'','', C) ) 164 | 165 | print ("-"*80) 166 | return Sij 167 | 168 | def elastic_anisotropy(S): 169 | #Elastic anisotropy of crystals is important since it correlates with the 170 | #possibility to induce micro-cracks in materials 171 | v=[] 172 | f = open('CONTCAR','r') 173 | lines = f.readlines() 174 | f.close() 175 | 176 | s = float(lines[1]) 177 | for i in range(2,5,1): 178 | l = s*float(lines[i].split()[0]), s*float(lines[i].split()[1]), s*float(lines[i].split()[2]) 179 | v.append( l ) 180 | v = np.mat(v) 181 | print("Reading lattice vectors into matrix form") 182 | print(v[:]) 183 | 184 | # l1, l2, l3 are the direction cosines 185 | n1 = np.linalg.norm(v[0]) 186 | n2 = np.linalg.norm(v[1]) 187 | n3 = np.linalg.norm(v[2]) 188 | l1 = math.degrees(math.acos(np.dot(v[0],np.transpose(v[1]))/(n1*n2))) 189 | l2 = math.degrees(math.acos(np.dot(v[1],np.transpose(v[2]))/(n2*n3))) 190 | l3 = math.degrees(math.acos(np.dot(v[2],np.transpose(v[0]))/(n3*n1))) 191 | print ("l's are direction Cosines:: l1={:6.6f} l2={:6.6f} l3={:6.6f}".format(l1, l2, l3) ) 192 | B = 1/(3*(S[0,0] + 2*S[0,1] )) 193 | G = 1/( S[3,3] +4*(S[0,0] - S[0,1] -1/(2*S[3,3]) ) * (l1**2 * l2**2 + l2**2 * l3**2 + l1**2 * l3**2) ) 194 | E = 1/( S[0,0] -2*(S[0,0] - S[0,1] -1/(2*S[3,3]) ) * (l1**2 * l2**2 + l2**2 * l3**2 + l1**2 * l3**2) ) 195 | print ("B={:6.6f} G={:6.6f} E={:6.6f}".format(B, G, E) ) 196 | 197 | ############ 198 | def local_lattice_distortion_DEF1(): 199 | #print ("The lattice distortion in paracrystals is measured by the lattice distortion parameter g") 200 | #print (Back.YELLOW + "Wang, S. Atomic structure modeling of multi-principal-element alloys by the principle") 201 | #print (Back.YELLOW + "of maximum entropy. Entropy 15, 5536–5548 (2013).") 202 | print (">"*10,"HUME ROTHERY RULE") 203 | C_i=C=0.2 ; r_avg = 0.0; del_sum=0.0 204 | elements = ["Nb", "Hf", "Ta", "Ti", "Zr"] 205 | eta = { 206 | "Nb" : 1.98, 207 | "Hf" : 2.08, 208 | "Ta" : 2.00, 209 | "Ti" : 1.76, 210 | "Zr" : 2.06, } 211 | 212 | print (" {element: atomic radius}") 213 | print (eta) 214 | 215 | for i in elements: 216 | r_avg = r_avg + C * eta[i] 217 | 218 | for j in elements: 219 | del_sum = del_sum + C * ( 1 - float(eta[j]) / r_avg )**2 220 | del_sum = 100 * np.sqrt(del_sum) 221 | print("HEA_atomic_size_mismatch: \u03B4={}".format(del_sum)) 222 | 223 | ############ 224 | def local_lattice_distortion_DEF2(): 225 | print (">"*10,"local_lattice_distortion_DEF2") 226 | print (" Song, H. et al. Local lattice distortion in high-entropy alloys.") 227 | print (" Phys. Rev. Mater. 1, 23404 (2017).") 228 | print (" (***) Different definition of the atomic radius for the description ") 229 | print (" of the local lattice distortion in HEAs") 230 | 231 | if not os.path.exists('POSCAR' and 'CONTCAR'): 232 | print ('>>> ERROR: POSCAR & CONTCAR does not exist (Both should be in the same directory)') 233 | sys.exit(0) 234 | print('Reading POSCAR and CONTCAR ... \n') 235 | 236 | x = []; y =[]; z=[] 237 | xp =[]; yp = []; zp = []; temp=0 238 | 239 | f = open('POSCAR','r') 240 | lines_poscar = f.readlines() 241 | f.close() 242 | 243 | f = open('CONTCAR','r') 244 | lines_contcar = f.readlines() 245 | f.close() 246 | 247 | file_P = ase.io.read('POSCAR') 248 | pos = file_P.get_cell_lengths_and_angles() 249 | print (CRED + "POSCAR=>Length&Angles->{}".format(pos) + CEND) 250 | file_C = ase.io.read('CONTCAR') 251 | con = file_C.get_cell_lengths_and_angles() 252 | print (CRED + "CONTCAR=>Length&Angles->{}".format(con) + CEND) 253 | print ("Cell vectors difference:: ",con-pos) 254 | 255 | sum_atoms = lines_poscar[6].split() ### reading 7th lines for reading # of atoms 256 | sum_atoms = [int(i) for i in sum_atoms] 257 | sum_atoms = sum(sum_atoms) 258 | 259 | for i in lines_poscar: 260 | if "Direct" in i: 261 | lp=lines_poscar.index(i) 262 | for j in lines_contcar: 263 | if "Direct" in j: 264 | lc=lines_contcar.index(j) 265 | 266 | for i in range(sum_atoms): 267 | x, y, z = lines_poscar[lp+1+i].split() 268 | xc, yc, zc = lines_contcar[lp+1+i].split() 269 | x = float(x); y = float(y); z = float(z) 270 | xc = float(xc); yc = float(yc); zc = float(zc) 271 | temp = temp + np.sqrt( (x-xc)**2 + (y-yc)**2 + (z-zc)**2 ) 272 | temp = temp/sum_atoms 273 | print("local lattice distortion (LLD): \u0394d={}".format(temp)) 274 | 275 | if __name__ == "__main__": 276 | 277 | S = mechanical_properties() 278 | print ("_"*30,"Elastic Anisotropy Analysis","_"*30) 279 | elastic_anisotropy(S) 280 | 281 | print ("") 282 | print ("_"*30,"Lattice Distortion Analysis","_"*30) 283 | #local_lattice_distortion_DEF1() 284 | print ("") 285 | local_lattice_distortion_DEF2() 286 | 287 | 288 | 289 | -------------------------------------------------------------------------------- /src/fit_energy_vs_vol.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | import matplotlib.pyplot as plt 3 | import matplotlib.ticker as ptk 4 | import pylab as pyl 5 | import matplotlib.style 6 | 7 | bohr_radius = 0.529177 8 | bohr32ang3 = 0.14818474347 9 | joule2hartree = 4.3597482 10 | joule2rydberg = joule2hartree/2. 11 | unitconv = joule2hartree/bohr_radius**3*10.**3 12 | 13 | def energy_vs_volume(): 14 | import fnmatch 15 | mypath = os.getcwd() 16 | os.system("rm energy-vs-volume energy-vs-strain") 17 | eV2Hartree=0.036749309 18 | Ang32Bohr3=6.74833304162 19 | 20 | E=[]; dir_list=[]; count = 0; dir_E=[]; 21 | vol_cell=[]; strain_file=[]; strain_value=[] # strain_value is deformation 22 | 23 | print (" >>>>> Extracting Energies from directories <<<<<<") 24 | for entry in os.listdir(mypath): 25 | if not os.path.exists('strain-01'): 26 | print (' ERROR: strain-* files does not exist. create a strain file for each deformation values.') 27 | sys.exit(0) 28 | if fnmatch.fnmatchcase(entry,'strain-*'): 29 | f = open(entry,'r') 30 | lines = f.readline() #Read first line only 31 | strain_value.append( float(lines) ) 32 | f.close() 33 | if os.path.isfile(os.path.join(mypath, entry)): 34 | strain_file.append(entry) 35 | 36 | if os.path.isdir(os.path.join(mypath, entry)): 37 | dir_list.append(entry) 38 | 39 | for file in os.listdir(entry): 40 | if file == "OUTCAR": 41 | filepath = os.path.join(entry, file) 42 | if not os.path.exists(filepath): 43 | print (' ERROR: OUTCAR does not exist here.') 44 | sys.exit(0) 45 | f = open(filepath,'r') 46 | lines = f.readlines() 47 | f.close() 48 | 49 | for i in lines: 50 | if " free energy TOTEN =" in i: 51 | m=float(i.split()[4]) 52 | if " volume of cell :" in i: 53 | v=float(i.split()[4]) 54 | vol_cell.append(v) 55 | E.append(m) 56 | count+=1 57 | print("# of folders detected: ", count) 58 | print ("Directory :%10.6s %14s %18s %25.20s " % ("Folder", "Energy(eV)", "Vol_of_cell(A^3)", "strain_deformation" )) 59 | 60 | for i in range(math.floor(count/2)): # 0 to 4 61 | print ("Folder name: %10.10s %16.8f %16.8f %16.12s %14.4f" %(dir_list[i], E[i], vol_cell[i], strain_file[i], strain_value[i] )) 62 | if (bool(math.floor(count/2))): 63 | i = math.floor(count/2) 64 | print(Back.GREEN + 'Folder name: %10.10s %16.8f %16.8f %16.12s %14.4f <--Ref' % (dir_list[i], E[i], vol_cell[i], strain_file[i], strain_value[i] )) 65 | print(Style.RESET_ALL, end="") 66 | for i in range(math.ceil(count/2), count, 1): 67 | print ("Folder name: %10.10s %16.8f %16.8f %16.12s %14.4f" %(dir_list[i], E[i], vol_cell[i], strain_file[i], strain_value[i] )) 68 | #rc = subprocess.Popen(['bash', 'extract_energy.sh']) 69 | 70 | print (colored('ENERGIES & VOLUMES ARE WRITTEN IN ATOMIC UNITS TO A FILE ','yellow'), end = '\n', flush=True) 71 | print (colored('IT WILL BE READ BY ELASTIC SCRIPTS FOR POSTPROCESSING eV-->Ha; A^3-->Bohr^3','yellow'), end = '\n', flush=True) 72 | 73 | file = open("energy-vs-volume",'w') 74 | for i in range(count): 75 | file.write ("%14.6f %14.6f\n" %(vol_cell[i] * Ang32Bohr3, E[i] * eV2Hartree)) 76 | file.close() 77 | 78 | file = open("energy-vs-strain",'w') 79 | for i in range(count): 80 | file.write ("%12.6f %14.6f\n" %(strain_value[i], E[i] * eV2Hartree)) 81 | file.close() 82 | ### 83 | 84 | ''' 85 | #####--------------------------------------------------------- 86 | # 5- FITTING ENERGY vs VOLUME CURVE from VASP OUTCAR file 87 | #####--------------------------------------------------------- 88 | ''' 89 | 90 | def fitting_energy_vs_volume_curve(): 91 | from sys import stdin 92 | import matplotlib.pyplot as plt 93 | import matplotlib.ticker as ptk 94 | import pylab as pyl 95 | import matplotlib.style 96 | 97 | bohr_radius = 0.529177 98 | bohr32ang3 = 0.14818474347 99 | joule2hartree = 4.3597482 100 | joule2rydberg = joule2hartree/2. 101 | unitconv = joule2hartree/bohr_radius**3*10.**3 102 | 103 | if (str(os.path.exists('energy-vs-volume'))=='False'): 104 | sys.exit("ERROR: file energy-vs-volume not found!\n") 105 | energy = []; volume = [] 106 | read_energy = open('energy-vs-volume',"r") 107 | 108 | while True: 109 | line = read_energy.readline() 110 | line = line.strip() 111 | if len(line) == 0: break 112 | energy.append(float(line.split()[1])) 113 | volume.append(float(line.split()[0])) 114 | volume,energy=sortvolume(volume,energy) 115 | 116 | print ("===============================") 117 | print ("Lattice symmetry codes" ) 118 | print ("-------------------------------") 119 | print ("1 --> Simple cubic (sc)" ) 120 | print ("2 --> Body-centered cubic (bcc)") 121 | print ("3 --> Face-centered cubic (fcc)") 122 | print ("-------------------------------") 123 | print ("0 --> Others") 124 | print ("===============================\n") 125 | scheck = input("Enter lattice symmetry code [default 0] >>>> ").replace(" ", "") 126 | 127 | ''' 128 | These factors are for the conversion from the conventional cell to primitive cell 129 | BCC: (a^3)/2 primitive cell volume 130 | FCC: (a^3)/4 primitive cell volume 131 | 132 | ''' 133 | 134 | isym = 0; factor = 1 135 | if ( scheck == "1" ): isym = 1 ; factor=1 ; slabel = "(sc) " 136 | if ( scheck == "2" ): isym = 2 ; factor=2 ; slabel = "(bcc)" 137 | if ( scheck == "3" ): isym = 3 ; factor=4 ; slabel = "(fcc)" 138 | print ("Verification lattice symmetry code >>>> %d " %(isym) ) 139 | #------------------------------------------------------------------------------- 140 | print ('%s' %('-'*105) ) 141 | print ('%20.25s %29.30s %21.30s %11.12s %18.30s' %("Opt_vol Bohr^3 (Ang^3)", "Lattice_const Bohr (A)", "Bulk_modulus [GPa]", "Log(chi)", "Polynomial_order")) 142 | print ('%s' %('-'*105) ) 143 | for order_of_fit in range(2, 11): #order of polynomial fitting 144 | if order_of_fit % 2 == 0: 145 | order_of_fit = int(order_of_fit) 146 | fitr = np.polyfit(volume,energy,order_of_fit) 147 | curv = np.poly1d(fitr) 148 | oned = np.poly1d(np.polyder(fitr,1)) # 149 | bulk = np.poly1d(np.polyder(fitr,2)) 150 | bpri = np.poly1d(np.polyder(fitr,3)) # 151 | vmin = np.roots(np.polyder(fitr)) 152 | dmin=[] 153 | for i in range(len(vmin)): 154 | if (abs(vmin[i].imag) < 1.e-10): 155 | if (volume[0] <= vmin[i] and vmin[i] <= volume[-1]): 156 | if(bulk(vmin[i]) > 0): dmin.append(vmin[i].real) 157 | 158 | xvol = np.linspace(volume[0],volume[-1],100) 159 | if (len(dmin) > 1): print ("WARNING: Multiple minima are found!\n") 160 | if (len(dmin) == 0): print ("WARNING: No minimum in the given xrange!\n") 161 | 162 | chi = 0 163 | for i in range(len(energy)): 164 | chi=chi+(energy[i]-curv(volume[i]))**2 165 | chi=math.sqrt(chi)/len(energy) 166 | #------------------------------------------------------------------------------- 167 | for i in range(len(dmin)): 168 | x0=dmin[len(dmin)-1-i] 169 | v0=dmin[len(dmin)-1-i] 170 | a0=(factor*v0)**(0.33333333333) 171 | b0=bulk(v0)*v0*unitconv 172 | #if (isym > 0): print ('Lattice constant = %5s %12.6f %12.6f' %(slabel,a0, a0*bohr_radius), '[Bohr, Angstrom]') 173 | if (isym > 0): 174 | print("%12.6f (%11.6f) %12.6f (%9.6f) %17.6f %13.2f %10d\n" %(v0, v0*bohr32ang3, a0, a0*bohr_radius, b0, math.log10(chi), order_of_fit), end="") 175 | else: 176 | print("%12.6f(%12.6f) %12.6f(%12.6f) %17.6f %13.2f %10d\n" %(v0, v0*bohr32ang3, a0, a0*bohr_radius, b0, math.log10(chi), order_of_fit), end="") 177 | print ('%s' %('-'*105) ) 178 | #------------------------------------------------------------------------------- 179 | 180 | xlabel = u'Volume [Bohr\u00B3]'; ylabel = r'Energy [Ha]' 181 | 182 | fontlabel=20 183 | fonttick=14 184 | 185 | params = {'ytick.minor.size': 6, 186 | 'xtick.major.pad': 8, 187 | 'ytick.major.pad': 4, 188 | 'patch.linewidth': 2., 189 | 'axes.linewidth': 2., 190 | 'lines.linewidth': 1.8, 191 | 'lines.markersize': 8.0, 192 | 'axes.formatter.limits': (-4, 6)} 193 | 194 | plt.rcParams.update(params) 195 | plt.subplots_adjust(left=0.21, right=0.93, 196 | bottom=0.18, top=0.88, 197 | wspace=None, hspace=None) 198 | 199 | yfmt = ptk.ScalarFormatter(useOffset=True,useMathText=True) 200 | 201 | figure = plt.figure(1, figsize=(9,9)) 202 | ax = figure.add_subplot(111) 203 | ax.text(0.5,-0.18,xlabel,size=fontlabel, transform=ax.transAxes,ha='center',va='center') 204 | ax.text(-0.25,0.5,ylabel,size=fontlabel, transform=ax.transAxes,ha='center',va='center',rotation=90) 205 | for line in ax.get_xticklines() + ax.get_yticklines(): 206 | line.set_markersize(6) 207 | line.set_markeredgewidth(2) 208 | plt.xticks(size=fonttick) 209 | plt.yticks(size=fonttick) 210 | pyl.grid(True) 211 | plt.plot(xvol,curv(xvol),'b-',label='n='+str(order_of_fit)+' fit') 212 | plt.plot(volume,energy,'go',label='calculated') 213 | plt.plot(dmin,curv(dmin),'ro') 214 | plt.legend(loc=9,borderaxespad=.8,numpoints=1) 215 | 216 | ymax = max(max(curv(xvol)),max(energy)) 217 | ymin = min(min(curv(xvol)),min(energy)) 218 | dxx = abs(max(xvol)-min(xvol))/18 219 | dyy = abs(ymax-ymin)/18 220 | ax.yaxis.set_major_formatter(yfmt) 221 | ax.set_xlim(min(xvol)-dxx,max(xvol)+dxx) 222 | ax.set_ylim(ymin-dyy,ymax+dyy) 223 | 224 | ax.xaxis.set_major_locator(MaxNLocator(7)) 225 | 226 | plt.savefig('PLOT.png',orientation='portrait',format='png') 227 | ### 228 | 229 | 230 | def sortvolume(s,e): 231 | ss=[]; ee=[]; ww=[] 232 | for i in range(len(s)): ww.append(s[i]) 233 | ww.sort() 234 | for i in range(len(s)): 235 | ss.append(s[s.index(ww[i])]) 236 | ee.append(e[s.index(ww[i])]) 237 | return ss, ee 238 | ### -------------------------------------------------------------------------------- /src/poscar.py: -------------------------------------------------------------------------------- 1 | import os, sys, spglib 2 | import math, glob 3 | import numpy as np 4 | import subprocess 5 | from os import listdir 6 | from os.path import isfile, join 7 | from pathlib import Path 8 | 9 | ang2atomic = 1.889725988579 # 1 A = 1.889725988579 [a.u] 10 | Ang32Bohr3 = 6.74833304162 # 1 A^3 = 6.7483330371 [a.u]^3 11 | 12 | def poscar(): 13 | if not os.path.exists('POSCAR'): 14 | print (' ERROR: POSCAR does not exist here.') 15 | sys.exit(0) 16 | print('Reading POSCAR/CONTCAR: \n') 17 | pos = []; kk = []; lattice = []; sum = 0 18 | file = open('POSCAR','r') or open('CONTCAR','r') 19 | 20 | firstline = file.readline() # IGNORE first line comment 21 | secondfline = file.readline() # scale 22 | Latvec1 = file.readline() 23 | #print ("Lattice vector 1:", (Latvec1), end = '') 24 | Latvec2 = file.readline() 25 | #print ("Lattice vector 2:", (Latvec2), end = '') 26 | Latvec3 = file.readline() 27 | #print ("Lattice vector 3:", (Latvec3), end = '') 28 | elementtype=file.readline().split() 29 | if (str.isdigit(elementtype[0])): 30 | sys.exit("VASP 4.X POSCAR detected. Please add the atom types") 31 | print ("Types of elements:", str(elementtype), end = '\n') 32 | numberofatoms=file.readline() 33 | Coordtype=file.readline() 34 | print ("Coordtype:", (Coordtype), end = '\n') 35 | 36 | ########################--------------------------------------------------------- 37 | print (">>>>>>>>>-------------------# of Atoms--------------------") 38 | nat = numberofatoms.split() 39 | nat = [int(i) for i in nat] 40 | print (nat) 41 | for i in nat: 42 | sum = sum + i 43 | numberofatoms = sum 44 | print ("Number of atoms:", (numberofatoms), end = '\n') 45 | ########################--------------------------------------------------------- 46 | 47 | #print (">>>>>>>>>---------------Atomic positions------------------") 48 | for x in range(int(numberofatoms)): 49 | coord = file.readline().split() 50 | coord = [float(i) for i in coord] 51 | pos = pos + [coord] 52 | pos = np.array(pos) 53 | #print (pos) 54 | 55 | file.close() 56 | 57 | ########################--------------------------------------------------------- 58 | a=[]; b=[]; c=[]; 59 | Latvec1=Latvec1.split() 60 | Latvec2=Latvec2.split() 61 | Latvec3=Latvec3.split() 62 | for ai in Latvec1: 63 | a.append(float(ai)) 64 | for bi in Latvec2: 65 | b.append(float(bi)) 66 | for ci in Latvec3: 67 | c.append(float(ci)) 68 | 69 | ########################--------------------------------------------------------- 70 | 71 | print (">>>>>>>>>---------------Lattice vectors distortions-----------------") 72 | lattice = np.array([a] + [b] + [c]) 73 | #determinant = np.linalg.det(lattice) 74 | lld = local_lattice_distortion(a,b,c) 75 | print ("lattice distortion parameter g: {}".format(lld) ) 76 | 77 | print (">>>>>>>>>---------------Space group-----------------") 78 | print (" ") 79 | sp, symm = space_group_analyse(lattice, pos) 80 | print ( sp, symm ) 81 | print (" ") 82 | print (">>>>>>>>>--------------------------------------------") 83 | print ('a=', a) 84 | print ('b=', b) 85 | print ('c=', c) 86 | gamma = math.degrees(math.acos(np.dot(a,b) / (np.linalg.norm(a) * np.linalg.norm(b)))) 87 | alpha = math.degrees(math.acos(np.dot(b,c) / (np.linalg.norm(b) * np.linalg.norm(c)))) 88 | beta = math.degrees(math.acos(np.dot(a,c) / (np.linalg.norm(a) * np.linalg.norm(c)))) 89 | print ("ratio c/a = %2f" %(np.linalg.norm(c) / np.linalg.norm(a) )) 90 | print ("-"*100) 91 | print ('||a||=%2f, \u03B1= %2f' %(np.linalg.norm(a), alpha)) 92 | print ('||b||=%2f \u03B2= %2f' %(np.linalg.norm(b), beta)) 93 | print ('||c||=%2f \u03B3= %2f' %(np.linalg.norm(c), gamma)) 94 | print ('Vol= %4.8f A^3; %4.8f [a.u]^3' %(volume(a,b,c,math.radians(alpha),math.radians(beta),math.radians(gamma) ))) 95 | ### 96 | 97 | def local_lattice_distortion(a1,b1,c1): 98 | #print ("The lattice distortion in paracrystals is measured by the lattice distortion parameter g") 99 | #print (Back.YELLOW + "Wang, S. Atomic structure modeling of multi-principal-element alloys by the principle") 100 | #print (Back.YELLOW + "of maximum entropy. Entropy 15, 5536–5548 (2013).") 101 | #print ("") 102 | a=np.linalg.norm(a1); b=np.linalg.norm(b1); c=np.linalg.norm(c1) 103 | d = np.array([a,b,c]) 104 | d_mean = np.mean(d); d_std = np.std(d) 105 | d_square_mean = (a**2 + b**2 + c**2)/3 106 | g = np.sqrt( d_square_mean/(d_mean)**2 - 1 ) 107 | return g 108 | ### 109 | # Song, H. et al. Local lattice distortion in high-entropy alloys. Phys. Rev. Mater. 1, 23404 (2017). 110 | # Senkov, O. N. & Miracle, D. B. Effect of the atomic size distribution on glass forming ability of amorphous metallic alloys. Mater. Res. Bull. 36, 2183–2198 (2001). 111 | # Takeuchi, A. et al. Entropies in alloy design for high-entropy and bulk glassy alloys. Entropy 15, 3810–3821 (2013). 112 | 113 | def local_lattice_distortion_DEF1(): 114 | #print ("The lattice distortion in paracrystals is measured by the lattice distortion parameter g") 115 | #print (Back.YELLOW + "Wang, S. Atomic structure modeling of multi-principal-element alloys by the principle") 116 | #print (Back.YELLOW + "of maximum entropy. Entropy 15, 5536–5548 (2013).") 117 | print ("+"*40,"HUME ROTHERY RULE","+"*40) 118 | C_i=C=0.2 ; r_avg = 0.0; del_sum=0.0 119 | elements = ["Nb", "Hf", "Ta", "Ti", "Zr"] 120 | eta = { 121 | "Nb" : 1.98, 122 | "Hf" : 2.08, 123 | "Ta" : 2.00, 124 | "Ti" : 1.76, 125 | "Zr" : 2.06, } 126 | 127 | print (" {element: atomic radius}") 128 | print (eta) 129 | 130 | for i in elements: 131 | r_avg = r_avg + C * eta[i] 132 | 133 | for j in elements: 134 | del_sum = del_sum + C * ( 1 - float(eta[j]) / r_avg )**2 135 | del_sum = 100 * np.sqrt(del_sum) 136 | print("HEA_atomic_size_mismatch: \u03B4={}".format(del_sum)) 137 | ### 138 | 139 | def local_lattice_distortion_DEF2(): 140 | print ("Song, H. et al. Local lattice distortion in high-entropy alloys.") 141 | print ("Phys. Rev. Mater. 1, 23404 (2017).") 142 | print ("_____| Different definition of the atomic radius for the description ") 143 | print (" of the local lattice distortion in HEAs") 144 | 145 | if not os.path.exists('POSCAR' and 'CONTCAR'): 146 | print (' ERROR: POSCAR & CONTCAR does not exist') 147 | sys.exit(0) 148 | print('Reading POSCAR and CONTCAR ... \n') 149 | 150 | x = []; y =[]; z=[] 151 | xp =[]; yp = []; zp = []; temp=0 152 | 153 | f = open('POSCAR','r') 154 | lines_poscar = f.readlines() 155 | f.close() 156 | 157 | f = open('CONTCAR','r') 158 | lines_contcar = f.readlines() 159 | f.close() 160 | 161 | sum_atoms = lines_poscar[6].split() ### reading 7th lines for reading # of atoms 162 | sum_atoms = [int(i) for i in sum_atoms] 163 | sum_atoms = sum(sum_atoms) 164 | 165 | for i in lines_poscar: 166 | if "Direct" in i: 167 | lp=lines_poscar.index(i) 168 | for j in lines_contcar: 169 | if "Direct" in j: 170 | lc=lines_contcar.index(j) 171 | 172 | for i in range(sum_atoms): 173 | x, y, z = lines_poscar[lp+1+i].split() 174 | xp, yp, zp = lines_contcar[lp+1+i].split() 175 | x = float(x); y = float(y); z = float(z) 176 | xp = float(xp); yp = float(yp); zp = float(zp) 177 | temp = temp + np.sqrt( (x-xp)**2 + (y-yp)**2 + (z-zp)**2 ) 178 | temp = temp/sum_atoms 179 | print("local lattice distortion: \u0394d={}".format(temp)) 180 | ### 181 | 182 | def space_group_analyse(lattice, pos): 183 | numbers = [1,2] 184 | cell = (lattice, pos, numbers) 185 | sp=spglib.get_spacegroup(cell, symprec=1e-5) 186 | symm=spglib.get_symmetry(cell, symprec=1e-5) 187 | #print(spglib.niggli_reduce(lattice, eps=1e-5)) 188 | 189 | #mesh = [8, 8, 8] 190 | #mapping, grid = spglib.get_ir_reciprocal_mesh(mesh, cell, is_shift=[0, 0, 0]) 191 | ## All k-points and mapping to ir-grid points 192 | #for i, (ir_gp_id, gp) in enumerate(zip(mapping, grid)): 193 | # print("%3d ->%3d %s" % (i, ir_gp_id, gp.astype(float) / mesh)) 194 | # 195 | ## Irreducible k-points 196 | #print("Number of ir-kpoints: %d" % len(np.unique(mapping))) 197 | #print(grid[np.unique(mapping)] / np.array(mesh, dtype=float)) 198 | # 199 | ## 200 | ## With shift 201 | ## 202 | #mapping, grid = spglib.get_ir_reciprocal_mesh(mesh, cell, is_shift=[1, 1, 1]) 203 | # 204 | ## All k-points and mapping to ir-grid points 205 | #for i, (ir_gp_id, gp) in enumerate(zip(mapping, grid)): 206 | # print("%3d ->%3d %s" % (i, ir_gp_id, (gp + [0.5, 0.5, 0.5]) / mesh)) 207 | # 208 | ## Irreducible k-points 209 | #print("Number of ir-kpoints: %d" % len(np.unique(mapping))) 210 | #print((grid[np.unique(mapping)] + [0.5, 0.5, 0.5]) / mesh) 211 | return sp, symm 212 | ### 213 | 214 | def poscar_VASP42VASP5(): 215 | if not os.path.exists('POSCAR' and 'POTCAR'): 216 | print (' ERROR: POSCAR does not exist here.') 217 | sys.exit(0) 218 | file1 = open("POSCAR",'r') 219 | line1 = file1.readlines() 220 | file1.close() 221 | 222 | file2 = open("POTCAR",'r') 223 | line2 = file2.readlines() 224 | file2.close() 225 | 226 | atom_number=[] 227 | for i in line1: 228 | if ("Direct" or "direct" or "d" or "D") in i: 229 | PP=line1.index(i) 230 | atom_number = line1[5].split() 231 | print(atom_number) 232 | 233 | elementtype=[]; count=0 234 | for i in line2: 235 | if ("VRHFIN") in i: 236 | count+=1 237 | #print (i.split('=')[1].split(':')[0]) 238 | elementtype.append(i.split('=')[1].split(':')[0]) 239 | 240 | test = open("POSCAR_W",'w') 241 | 242 | for i in range(5): 243 | test.write( line1[i] ) 244 | 245 | for j in elementtype: 246 | test.write("\t" + j) 247 | test.write("\n" ) 248 | 249 | for j in atom_number: 250 | test.write("\t" + j ) 251 | test.write("\n" ) 252 | 253 | test.write("Selective dynamics") 254 | test.write("\n" ) 255 | 256 | for i in range(len(line1)-PP): 257 | test.write(line1[PP+i] ) 258 | 259 | test.close() 260 | 261 | print (" File is converted: POSCAR_W") 262 | ### 263 | 264 | 265 | 266 | #### math.sin function takes argument in radians ONLY 267 | def volume(a,b,c,alpha,beta,gamma): 268 | ang2atomic = 1.889725988579 # 1 A = 1.889725988579 [a.u] 269 | Ang32Bohr3 = 6.74833304162 # 1 A^3 = 6.7483330371 [a.u]^3 270 | 271 | length = np.linalg.norm(a) * np.linalg.norm(b) * np.linalg.norm(c) 272 | volume = length * ( np.sqrt(1 + 2 * math.cos(alpha) * math.cos(beta) * math.cos(gamma) - math.cos(alpha)**2 - math.cos(beta)**2 - math.cos(gamma)**2) ) 273 | vol_au = volume * Ang32Bohr3 274 | return volume, vol_au 275 | 276 | -------------------------------------------------------------------------------- /src/strain.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | #_______________________________________________________________________________ 4 | 5 | from numpy import * 6 | import subprocess 7 | import os.path 8 | import shutil 9 | import numpy, scipy 10 | import math 11 | import sys, os 12 | import matplotlib.pyplot as plt 13 | from colorama import Fore, Back, Style, init 14 | init(autoreset=True) 15 | 16 | #_______________________________________________________________________________ 17 | 18 | def Elastic_strain(): 19 | print("*"*80) 20 | print ("________| http://exciting-code.org/nitrogen-energy-vs-strain-calculations") 21 | print ("________| \u03B7 = \u03B5 + 1/2*\u03B5**2") 22 | print ("________| r' = (I + \u03B5) * r ") 23 | print ("________| Deformation uses Voigt notation.") 24 | print("*"*80) 25 | 26 | if (str(os.path.exists('CONTCAR'))=='False'): 27 | sys.exit("ERROR: Input file CONTCAR not found!\n") 28 | 29 | maximum_strain = float(input("\nEnter maximum Lagrangian strain [smax] >>>> ")) 30 | if (maximum_strain == 0): 31 | work_directory = 'workdir' 32 | if (os.path.exists(work_directory)): shutil.rmtree(work_directory) 33 | os.mkdir(work_directory) 34 | 35 | os.system("cp CONTCAR workdir/CONTCAR-01") 36 | output_info = open('workdir/INFO-elastic-constants',"w") 37 | output_info.write("\nMaximum Lagrangian strain = 0" ) 38 | output_info.write("\nNumber of strain values = 1", ) 39 | output_info.write("\nVolume of equilibrium unit cell = 1.0 [A]^3",) 40 | output_info.write("\nDeformation code = 000000", ) 41 | output_info.write("\nDeformation label = single\n" ) 42 | output_info.close() 43 | 44 | output_eta = open('workdir/strain-01',"w") 45 | output_info.write("0.00") 46 | output_eta.close() 47 | print 48 | sys.exit("Single unstrained calculation\n") 49 | 50 | if (1 < maximum_strain or maximum_strain < 0): 51 | sys.exit("ERROR: Maximum Lagrangian strain is out of range [0-1]!\n") 52 | strain_points = int(input("\nEnter the number of strain values in [-smax,smax] >>>> ")) 53 | strain_points = int(abs(strain_points)) 54 | if (3 > strain_points or strain_points > 99): 55 | sys.exit("ERROR: Number of strain values is out of range [3-99]!\n") 56 | 57 | print(Style.RESET_ALL) 58 | print (Back.GREEN + "------------------------------------------------------------------------" ) 59 | print (Back.GREEN + " List of deformation codes for strains in Voigt notation" ) 60 | print (Back.GREEN + "------------------------------------------------------------------------" ) 61 | print (Back.YELLOW + " 0 => ( eta, eta, eta, 0, 0, 0) | volume strain " ) 62 | print (Back.YELLOW + " 1 => ( eta, 0, 0, 0, 0, 0) | linear strain along x " ) 63 | print (Back.GREEN + " 2 => ( 0, eta, 0, 0, 0, 0) | linear strain along y " ) 64 | print (Back.GREEN + " 3 => ( 0, 0, eta, 0, 0, 0) | linear strain along z " ) 65 | print (Back.GREEN + " 4 => ( 0, 0, 0, eta, 0, 0) | yz shear strain" ) 66 | print (Back.GREEN + " 5 => ( 0, 0, 0, 0, eta, 0) | xz shear strain" ) 67 | print (Back.GREEN + " 6 => ( 0, 0, 0, 0, 0, eta) | xy shear strain" ) 68 | print (Back.YELLOW + " 7 => ( 0, 0, 0, eta, eta, eta) | shear strain along (111)" ) 69 | print (Back.GREEN + " 8 => ( eta, eta, 0, 0, 0, 0) | xy in-plane strain " ) 70 | print (Back.GREEN + " 9 => ( eta, -eta, 0, 0, 0, 0) | xy in-plane shear strain" ) 71 | print (Back.GREEN + " 10 => ( eta, eta, eta, eta, eta, eta) | global strain" ) 72 | print (Back.GREEN + " 11 => ( eta, 0, 0, eta, 0, 0) | mixed strain" ) 73 | print (Back.GREEN + " 12 => ( eta, 0, 0, 0, eta, 0) | mixed strain" ) 74 | print (Back.GREEN + " 13 => ( eta, 0, 0, 0, 0, eta) | mixed strain" ) 75 | print (Back.GREEN + " 14 => ( eta, eta, 0, eta, 0, 0) | mixed strain" ) 76 | print (Back.GREEN + "------------------------------------------------------------------------" ) 77 | print(Style.RESET_ALL) 78 | 79 | deformation_code = int(input("\nEnter deformation code >>>> ")) 80 | if (0 > deformation_code or deformation_code > 14): 81 | sys.exit("ERROR: Deformation code is out of range [0-14]!\n") 82 | 83 | if (deformation_code == 0 ): dc='EEE000' 84 | if (deformation_code == 1 ): dc='E00000' 85 | if (deformation_code == 2 ): dc='0E0000' 86 | if (deformation_code == 3 ): dc='00E000' 87 | if (deformation_code == 4 ): dc='000E00' 88 | if (deformation_code == 5 ): dc='0000E0' 89 | if (deformation_code == 6 ): dc='00000E' 90 | if (deformation_code == 7 ): dc='000EEE' 91 | if (deformation_code == 8 ): dc='EE0000' 92 | if (deformation_code == 9 ): dc='Ee0000' 93 | if (deformation_code == 10): dc='EEEEEE' 94 | if (deformation_code == 11): dc='E00E00' 95 | if (deformation_code == 12): dc='E000E0' 96 | if (deformation_code == 13): dc='E0000E' 97 | if (deformation_code == 14): dc='EE0E00' 98 | 99 | #------------------------------------------------------------------------------- 100 | file1 = open("CONTCAR",'r') 101 | line1 = file1.readlines() 102 | file1.close() 103 | for i in line1: 104 | if ("Direct" or "direct" or "d" or "D") in i: 105 | PP=line1.index(i) 106 | #------------------------------------------------------------------------------- 107 | 108 | input_obj = open("CONTCAR","r") 109 | 110 | firstline = input_obj.readline() # IGNORE first line comment 111 | xml_scale = float(input_obj.readline()) # scale 112 | Latvec1 = input_obj.readline() 113 | Latvec2 = input_obj.readline() 114 | Latvec3 = input_obj.readline() 115 | elementtype = input_obj.readline().split() 116 | if (str.isdigit(elementtype[0])): 117 | sys.exit("VASP 4.X POSCAR detected. Please add the atom types") 118 | atom_number = input_obj.readline() 119 | Coordtype = input_obj.readline() 120 | nat = atom_number.split() 121 | nat = [int(i) for i in nat] 122 | print ("Number of atoms in the cell {} ".format( sum(nat)) ) 123 | 124 | input_obj.close() 125 | #------------------------------------------------------------------------------- 126 | a=[]; b=[]; c=[]; 127 | Latvec1 = Latvec1.split() 128 | Latvec2 = Latvec2.split() 129 | Latvec3 = Latvec3.split() 130 | for ai in Latvec1: a.append(float(ai)) 131 | for bi in Latvec2: b.append(float(bi)) 132 | for ci in Latvec3: c.append(float(ci)) 133 | 134 | xml_basevect = numpy.array([a] + [b] + [c]) 135 | print ("{}".format(xml_basevect),end="\n" ) 136 | axis_matrix = numpy.array(xml_basevect) 137 | determinant = numpy.linalg.det(axis_matrix) 138 | volume = numpy.abs(determinant*xml_scale**3) 139 | print("Equilibrium volume of cell {} ".format(volume) ) 140 | #------------------------------------------------------------------------------- 141 | work_directory = 'workdir' 142 | if (len(sys.argv) > 1): work_directory = sys.argv[1] 143 | if (os.path.exists(work_directory)): shutil.rmtree(work_directory) 144 | os.mkdir(work_directory) 145 | os.chdir(work_directory) 146 | 147 | output_info = open('INFO-elastic-constants',"w") 148 | 149 | output_info.write("\nMaximum Lagrangian strain = {}".format( maximum_strain )) 150 | output_info.write("\nNumber of strain values = {}".format(strain_points)) 151 | output_info.write("\nVolume of equilibrium unit cell = {} [A]^3".format(volume)) 152 | output_info.write("\nDeformation code = {}".format(deformation_code)) 153 | output_info.write("\nDeformation label = {}".format(dc, "\n")) 154 | 155 | output_info.close() 156 | 157 | #------------------------------------------------------------------------------- 158 | 159 | delta=strain_points-1 ;# print (delta) 160 | convert=1 161 | if (strain_points <= 1): 162 | strain_points=1 163 | convert=-1 164 | delta=1 165 | 166 | eta_step=2*maximum_strain/delta 167 | #print(eta_step) 168 | #------------------------------------------------------------------------------- 169 | 170 | for i in range(0,strain_points): 171 | 172 | #------------------------------------------------------------------------------- 173 | 174 | eta=i*eta_step-maximum_strain*convert 175 | #print (eta) 176 | if (i+1 < 10): strainfile = 'strain-0'+str(i+1) 177 | else: strainfile = 'strain-'+str(i+1) 178 | output_str = open(strainfile,"w") 179 | output_str.write( "{:11.8f}".format(eta) ) 180 | output_str.close() 181 | 182 | if (abs(eta) < 0): eta=0 183 | ep=eta 184 | if (eta < 0.0): em=abs(eta) 185 | else: em=-eta 186 | 187 | #------------------------------------------------------------------------------- 188 | 189 | e=[] 190 | for j in range(6): 191 | ev=0 192 | if (dc[j:j+1] == 'E' ): ev=ep; #print (ev) 193 | elif(dc[j:j+1] == 'e' ): ev=em 194 | elif(dc[j:j+1] == '0' ): ev=0 195 | else: print ("==> "), dc; sys.exit("ERROR: deformation code not allowed!") 196 | e.append(ev) 197 | e = numpy.array(e) 198 | #print(numpy.array(e)) 199 | #------------------------------------------------------------------------------- 200 | 201 | eta_matrix=numpy.mat( [ 202 | [ e[0] , e[5]/2, e[4]/2], 203 | [ e[5]/2, e[1] , e[3]/2], 204 | [ e[4]/2, e[3]/2, e[2] ] ], dtype=float32 ) 205 | if i == 6: # for test purposes 206 | print (eta_matrix) 207 | one_matrix=numpy.identity(3) 208 | 209 | #------------------------------------------------------------------------------- 210 | 211 | norma=1 212 | inorma=0 213 | eps_matrix=eta_matrix 214 | 215 | if (numpy.linalg.norm(eta_matrix) > 0.7):sys.exit("ERROR: too large deformation!") 216 | 217 | while ( norma > 0.0 ): 218 | x=eta_matrix - (1/2) * numpy.dot(eps_matrix,eps_matrix) 219 | norma=numpy.linalg.norm(x-eps_matrix) 220 | #print(norma) 221 | eps_matrix=x 222 | inorma=inorma+1 223 | 224 | def_matrix=one_matrix+eps_matrix 225 | #print (eps_matrix) 226 | #if i == 6: 227 | # print ( numpy.dot(def_matrix,axis_matrix) ) 228 | # print ( "{} {}" .format(def_matrix, axis_matrix ) ) 229 | # print ( numpy.transpose(numpy.dot(def_matrix,numpy.transpose(axis_matrix)) ) ) 230 | new_axis_matrix=numpy.transpose(numpy.dot(def_matrix,numpy.transpose(axis_matrix))) 231 | nam=numpy.mat( new_axis_matrix, dtype=float32 ) 232 | 233 | #------------------------------------------------------------------------------- 234 | 235 | if (i+1 < 10): 236 | outputfile = 'POSCAR-0'+str(i+1) 237 | else: 238 | outputfile = 'POSCAR-'+str(i+1) 239 | output_obj = open(outputfile,"w") 240 | output_obj.write(firstline) 241 | output_obj.write("{:10.8f}".format((xml_scale))+"\n") 242 | 243 | for j in range(3): 244 | output_obj.write("{:22.16f} {:22.16f} {:22.16f}\n".format( (nam[j,0]), (nam[j,1]), (nam[j,2]) ) ) 245 | #output_obj.write( str(fmt%nam[j,0])+str(fmt%nam[j,1])+str(fmt%nam[j,2])+"\n" ) 246 | 247 | for j in elementtype: 248 | output_obj.write("\t" + j) 249 | output_obj.write("\n" ) 250 | 251 | for j in atom_number: 252 | output_obj.write( "{}".format(j) ) 253 | 254 | for i in range(len(line1)-PP): 255 | output_obj.write(line1[PP+i] ) 256 | output_obj.close() 257 | 258 | #------------------------------------------------------------------------------- 259 | os.chdir('../') 260 | print 261 | 262 | #plt.imshow(numpy.log(numpy.abs(numpy.fft.fftn(nam))**2)) 263 | #plt.show() 264 | --------------------------------------------------------------------------------