├── LICENSE ├── Makefile ├── README.md ├── change.log ├── src ├── about.cpp ├── about.h ├── bonds.cpp ├── bonds.h ├── cif.cpp ├── cif.h ├── constants.cpp ├── constants.h ├── crystalMaker.cpp ├── crystalMaker.h ├── diffraction.cpp ├── diffraction.h ├── electrostatic.cpp ├── electrostatic.h ├── elements.cpp ├── elements.h ├── espresso.cpp ├── espresso.h ├── ewald.cpp ├── ewald.h ├── extPotential.cpp ├── extPotential.h ├── fileSystem.cpp ├── fileSystem.h ├── findsym.cpp ├── findsym.h ├── ga.h ├── gaPredict.cpp ├── gaPredict.h ├── help.cpp ├── help.h ├── interstitial.cpp ├── interstitial.h ├── iso.cpp ├── iso.h ├── json.cpp ├── json.h ├── kmc.cpp ├── kmc.h ├── kpoints.cpp ├── kpoints.h ├── language.cpp ├── language.h ├── launcher.cpp ├── launcher.h ├── list.h ├── locPotential.cpp ├── locPotential.h ├── mint.cpp ├── mintStructure.cpp ├── mintStructure.h ├── mtwist.c ├── mtwist.h ├── multi.cpp ├── multi.h ├── num.h ├── output.cpp ├── output.h ├── pairPotential.cpp ├── pairPotential.h ├── pdf.cpp ├── pdf.h ├── phonons.cpp ├── phonons.h ├── pointGroup.cpp ├── pointGroup.h ├── potential.cpp ├── potential.h ├── randistrs.c ├── randistrs.h ├── random.cpp ├── random.h ├── randomStructure.cpp ├── randomStructure.h ├── relax.cpp ├── relax.h ├── settings.cpp ├── settings.h ├── spaceGroup.cpp ├── spaceGroup.h ├── structureIO.cpp ├── structureIO.h ├── symmetry.cpp ├── symmetry.h ├── text.cpp ├── text.h ├── timer.cpp ├── timer.h ├── unique.cpp ├── unique.h ├── vasp.cpp └── vasp.h └── update.sh /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER 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 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /change.log: -------------------------------------------------------------------------------- 1 | 2013.08.29 2 | * Linked to blas/lapack 3 | 4 | 2013.04.30 5 | * Major source code update 6 | * Key points: 7 | - Improvement of primitive containers 8 | - Faster math routines 9 | - Updates to algorithms throughout the code with improved stability 10 | 11 | -------------------------------------------------------------------------------- /src/about.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #include "about.h" 24 | #include "output.h" 25 | 26 | 27 | 28 | /* void About::print() 29 | * 30 | * Print information about the program 31 | */ 32 | 33 | void About::print() 34 | { 35 | PrintMethod origMethod = Output::method(); 36 | Output::method(STANDARD); 37 | 38 | Output::newline(); 39 | Output::print("Materials Interface (mint) "); 40 | #if defined(VERSION) 41 | Output::print("v"); 42 | Output::print(VERSION); 43 | #else 44 | Output::print("unknown version"); 45 | #endif 46 | 47 | Output::newline(); 48 | Output::newline(); 49 | Output::print("Compiled on "); 50 | #ifdef COMP 51 | Output::print(COMP); 52 | #else 53 | Output::print("unknown date at unknown time"); 54 | #endif 55 | Output::newline(); 56 | Output::print("MPI support: "); 57 | #ifdef MINT_MPI 58 | Output::print("on"); 59 | #else 60 | Output::print("off"); 61 | #endif 62 | 63 | Output::newline(); 64 | Output::newline(); 65 | Output::newline(); Output::print("Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton"); 66 | Output::newline(); 67 | Output::newline(); Output::print("Mint is free software: you can redistribute it and/or modify it under the"); 68 | Output::newline(); Output::print("terms of the GNU Lesser General Public License as published by the Free"); 69 | Output::newline(); Output::print("Software Foundation, either version 3 of the License, or (at your option)"); 70 | Output::newline(); Output::print("any later version."); 71 | Output::newline(); 72 | Output::newline(); Output::print("Mint is distributed in the hope that it will be useful, but WITHOUT ANY"); 73 | Output::newline(); Output::print("WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS"); 74 | Output::newline(); Output::print("FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for"); 75 | Output::newline(); Output::print("more details."); 76 | Output::newline(); 77 | Output::newline(); Output::print("You should have received a copy of the GNU Lesser General Public License"); 78 | Output::newline(); Output::print("along with Mint. If not, see ."); 79 | Output::newline(); 80 | Output::newline(); Output::print("Contact: Kyle Michel (kylemichel@gmail.com)"); 81 | Output::newline(); Output::print(" Logan Ward (LoganWard2012@u.northwestern.edu)"); 82 | 83 | Output::method(origMethod); 84 | } 85 | 86 | -------------------------------------------------------------------------------- /src/about.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef ABOUT_H 24 | #define ABOUT_H 25 | 26 | 27 | 28 | // About message 29 | namespace About 30 | { 31 | void print(); 32 | } 33 | 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/bonds.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | #ifndef BONDS_H 23 | #define BONDS_H 24 | 25 | 26 | 27 | #include "iso.h" 28 | #include "elements.h" 29 | 30 | 31 | 32 | // Class to store information about a single bond between elements 33 | class Bond 34 | { 35 | 36 | // Variables 37 | Element _elem1; 38 | Element _elem2; 39 | double _min; 40 | double _max; 41 | 42 | public: 43 | 44 | // Functions 45 | void set(const Element& elem1, const Element& elem2, double min, double max) 46 | { _elem1 = elem1; _elem2 = elem2; _min = min; _max = max; } 47 | 48 | // Access functions 49 | const Element& elem1() const { return _elem1; } 50 | const Element& elem2() const { return _elem2; } 51 | double min() const { return _min; } 52 | double max() const { return _max; } 53 | }; 54 | 55 | 56 | 57 | // Class to get information about bonds 58 | class Bonds 59 | { 60 | public: 61 | static OList find(const ISO& iso); 62 | // static OList::D2 findAll(const ISO& iso); 63 | }; 64 | 65 | 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/cif.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef CIF_H 24 | #define CIF_H 25 | 26 | 27 | 28 | #include "iso.h" 29 | #include "text.h" 30 | #include "list.h" 31 | #include "fileSystem.h" 32 | 33 | 34 | 35 | // Class for CIF files 36 | class CIF 37 | { 38 | 39 | // Tags 40 | enum Tag {tag_unknown, atom_site_label, atom_site_type_symbol, atom_site_fract_x, atom_site_fract_y, \ 41 | atom_site_fract_z, atom_site_occupancy, cell_length_a, cell_length_b, cell_length_c, cell_angle_alpha, \ 42 | cell_angle_beta, cell_angle_gamma, space_group_IT_number, space_group_symop_operation_xyz, \ 43 | symmetry_Int_Tables_number, space_group_name_H_M, space_group_name_Hall, \ 44 | symmetry_equiv_pos_as_xyz, chemical_formula_sum, cell_formula_units_Z}; 45 | 46 | // Functions 47 | static bool checkTag(Tag tag, OList& curLine, Vector3D& lengths, Vector3D& angles, \ 48 | Word& spaceGroupName, OList& elements, List& composition, int& Z); 49 | static Words getLine(const OList& line); 50 | static Tag getTag(const Word& word); 51 | static void getElementAndNumber(Word& element, Word& number, const Word& word); 52 | 53 | public: 54 | 55 | // Read structure 56 | static ISO read(const Text& content, double clusterTol = 0.1); 57 | static ISO read(const Word& file, double clusterTol = 0.1) { return read(Read::text(file), clusterTol); } 58 | 59 | // Write structure 60 | static void write(const Word& file, const ISO& iso, double tol); 61 | 62 | // Check if file is in correct format 63 | static bool isFormat(const Text& content); 64 | static bool isFormat(const Word& file) { return isFormat(Read::text(file)); } 65 | }; 66 | 67 | 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/constants.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #include "constants.h" 24 | #include 25 | 26 | 27 | 28 | double Constants::pi = 2.0*acos(0.0); // Pi 29 | double Constants::kb = 0.000086173324; // Boltmann constant: eV/ 30 | double Constants::eps0 = 0.005526349961239601; 31 | double Constants::h = 4.135667516e-15; 32 | double Constants::hbar = 6.58211928e-16; 33 | double Constants::c = 299792458; // Speed of light: meters 34 | double Constants::meter = 1e10; // 1 meter: angstroms 35 | double Constants::kg = 6.02214129e26; // 1 kg: amu 36 | double Constants::joule = 6.24150934e18; // 1 joule: eV 37 | double Constants::Ry = 13.6056981; // 1 Rydberg: eV 38 | double Constants::bohr = 0.529177249; // 1 Bohr: angstroms 39 | -------------------------------------------------------------------------------- /src/constants.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef CONSTANTS_H 24 | #define CONSTANTS_H 25 | 26 | 27 | 28 | // Constants 29 | namespace Constants 30 | { 31 | extern double pi; 32 | extern double kb; 33 | extern double eps0; 34 | extern double h; 35 | extern double hbar; 36 | extern double c; 37 | extern double meter; 38 | extern double kg; 39 | extern double joule; 40 | extern double Ry; 41 | extern double bohr; 42 | } 43 | 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/crystalMaker.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef CRYSTALMAKER_H 24 | #define CRYSTALMAKER_H 25 | 26 | 27 | 28 | #include "iso.h" 29 | #include "text.h" 30 | 31 | 32 | 33 | // CrystalMaker structure functions 34 | class CrystalMaker 35 | { 36 | public: 37 | static void write(const Word& file, const ISO& iso); 38 | }; 39 | 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/electrostatic.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | #include "electrostatic.h" 25 | #include "text.h" 26 | #include "pairPotential.h" 27 | 28 | /** 29 | * Read in options from file. See class documentation for those options 30 | * @param input Text input from file 31 | */ 32 | void Electrostatic::set(const Text& input) { 33 | 34 | // Read in elements 35 | for (int pos=1; pos < input[0].length(); pos += 3) { 36 | try { 37 | _elements += Element::find(input[0][pos], false); 38 | _charges += atof(input[0][pos+1].array()); 39 | _radii.push_back(atof(input[0][pos+2].array())); 40 | } catch(...) { 41 | readError(input[0]); 42 | } 43 | } 44 | 45 | // Read in other options 46 | setEwaldOptions(input, true); 47 | 48 | // Define the hard-sphere potentials 49 | _potentials.clear(); 50 | for (int elem1=0; elem1 < _elements.length(); elem1++) { 51 | for (int elem2=elem1; elem2 < _elements.length(); elem2++) { 52 | HardSphere hs; 53 | hs.setForce(1000.0); 54 | hs.setRadius(_radii[elem1] + _radii[elem2]); 55 | hs.setElementOne(_elements[elem1]); 56 | hs.setElementTwo(_elements[elem2]); 57 | _potentials.push_back(hs); 58 | } 59 | } 60 | } 61 | 62 | void Electrostatic::evaluate(const ISO& iso, double* totalEnergy, OList* totalForces) const { 63 | Ewald::evaluate(iso, totalEnergy, totalForces); 64 | 65 | for (int i=0; i<_potentials.size(); i++) { 66 | _potentials[i].evaluate(iso, totalEnergy, totalForces); 67 | } 68 | } 69 | 70 | void Electrostatic::evaluate(const ISO& iso, const Symmetry& symmetry, double* totalEnergy, OList* totalForces) const { 71 | Ewald::evaluate(iso, symmetry, totalEnergy, totalForces); 72 | 73 | for (int i=0; i<_potentials.size(); i++) { 74 | _potentials[i].evaluate(iso, symmetry, totalEnergy, totalForces); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/electrostatic.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | #ifndef POTENTIALPEGS_H 22 | #define POTENTIALPEGS_H 23 | 24 | #include "locPotential.h" 25 | #include "ewald.h" 26 | #include "text.h" 27 | #include "pairPotential.h" 28 | #include 29 | 30 | /** 31 | * Defines the electrostatic potential similar to that used in PEGS 32 | * 33 | * E(R) = [columbic repulsion] + [hard-sphere potential] 34 | * 35 | * PEGS (as implemented by Eric Majzoub) uses soft-sphere potential that is only 36 | * taken into account when ions overlap. The discontinuity of this function causes 37 | * problems during relaxation. To overcome this problem, this implementation uses 38 | * the following function to represent hard-sphere interaction 39 | * 40 | * E(R) = R < R_HS ? a * (exp((R - R_HS) ^ 2) - 1) : 0 41 | * 42 | * This function has the advantage being having continuous second and third derivatives 43 | * with respect to R, which allows it to be used with most molecular-dynamics codes. 44 | * (This is kind of how LAMMPS does it: 45 | * Thank you, Steve Plimpton) 46 | * 47 | * The parameter a is chosen to be on the order of 1000, which keeps the minimum distance for a 48 | * pair of oppositely charged atoms to within 0.1 A of the hard-sphere radius for 49 | * reasonable charges. 50 | * 51 | * Input format: <element #1 Symbol, charge, radius> < <that data for each other element> 52 | * 53 | * Options: See options for Ewald (in set) 54 | * 55 | */ 56 | class Electrostatic : public Ewald { 57 | 58 | // Hard-sphere radius of each element (same order as inherited _elements array) 59 | vector _radii; 60 | 61 | // Hard sphere potentials 62 | vector _potentials; 63 | 64 | public: 65 | 66 | void set(const Text& input); 67 | 68 | virtual void evaluate(const ISO& iso, double* energy, OList* forces) const; 69 | virtual void evaluate(const ISO& iso, const Symmetry& symmetry, double* totalEnergy, OList* totalForces) const; 70 | 71 | }; 72 | 73 | #endif /* POTENTIALPEGS_H */ 74 | 75 | -------------------------------------------------------------------------------- /src/elements.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | #ifndef ELEMENTS_H 23 | #define ELEMENTS_H 24 | 25 | 26 | 27 | #include "text.h" 28 | 29 | 30 | 31 | // Class to store information about a single element 32 | class Element 33 | { 34 | 35 | // Variables 36 | int _number; 37 | int _isotope; 38 | Word _symbol; 39 | Word _name; 40 | double _mass; 41 | double _radius; 42 | 43 | // Functions 44 | static int getNumber(const char* value, bool useNumber); 45 | static int getNumber(const Word& value, bool useNumber) { return getNumber(value.array(), useNumber); } 46 | // static Element getByNumber(int num); 47 | 48 | public: 49 | static Element getByNumber(int num); 50 | // Constructors 51 | Element() { _number = _isotope = _mass = _radius = 0; } 52 | Element(const Element& rhs) { *this = rhs; } 53 | Element(int inNumber, int inIsotope, const char* inSymbol, const char* inName, double inMass, double radius) 54 | { set(inNumber, inIsotope, inSymbol, inName, inMass, radius); } 55 | 56 | // Setup functions 57 | void clear(); 58 | Element& operator= (const Element& rhs); 59 | void number(int input) { _number = input; } 60 | void isotope(int input) { _isotope = input; } 61 | void symbol(const char* input) { _symbol = input; } 62 | void symbol(const Word& input) { _symbol = input; } 63 | void name(const char* input) { _name = input; } 64 | void name(const Word& input) { _name = input; } 65 | void mass(double input) { _mass = input; } 66 | void radius(double input) { _radius = input; } 67 | void set(int inNumber, int inIsotope, const char* inSymbol, const char* inName, double inMass, double inRadius); 68 | void set(int inNumber, int inIsotope, const Word& inSymbol, const Word& inName, double inMass, double inRadius); 69 | 70 | // General functions 71 | bool operator== (const Element& rhs) const { return ((_number == rhs._number) && (_isotope == rhs._isotope)); } 72 | bool operator!= (const Element& rhs) const { return ((_number != rhs._number) || (_isotope != rhs._isotope)); } 73 | 74 | // Access functions 75 | int number() const { return _number; } 76 | int isotope() const { return _isotope; } 77 | const Word& symbol() const { return _symbol; } 78 | const Word& name() const { return _name; } 79 | double mass() const { return _mass; } 80 | double radius() const { return _radius; } 81 | 82 | // Static member functions 83 | static Element find(const char* value, bool useNumber = true, bool quitIfNotFound = false); 84 | static Element find(const Word& value, bool useNumber = true, bool quitIfNotFound = false) 85 | { return find(value.array(), useNumber, quitIfNotFound); } 86 | static bool isElement(const char* value, bool useNumber = true) { return (getNumber(value, useNumber) != 0); } 87 | static bool isElement(const Word& value, bool useNumber = true) { return (getNumber(value, useNumber) != 0); } 88 | }; 89 | 90 | 91 | 92 | /* inline void Element::clear() 93 | * 94 | * Clear data in Element object 95 | */ 96 | 97 | inline void Element::clear() 98 | { 99 | _number = 0; 100 | _isotope = 0; 101 | _symbol.clear(); 102 | _name.clear(); 103 | _mass = 0; 104 | _radius = 0; 105 | } 106 | 107 | 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /src/espresso.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef ESPRESSO_H 24 | #define ESPRESSO_H 25 | 26 | 27 | 28 | #include "iso.h" 29 | #include "elements.h" 30 | #include "kpoints.h" 31 | #include "text.h" 32 | #include "list.h" 33 | #include "num.h" 34 | #include "fileSystem.h" 35 | 36 | 37 | 38 | // Namespace to store quantum espresso functionality 39 | namespace Espresso 40 | { 41 | 42 | // Classes 43 | class Job; 44 | class Files; 45 | 46 | // Enumerated types 47 | enum Calculation {EC_NONE, EC_SINGLE, EC_RELAX_ALL, EC_RELAX_POSITIONS}; 48 | enum Accuracy {EA_UNKNOWN, EA_HIGH, EA_NORMAL, EA_LOW}; 49 | enum Material {EM_UNKNOWN, EM_METAL, EM_INSULATOR}; 50 | 51 | // Functions 52 | Accuracy accuracy(const Word& word); 53 | Word accuracy(Accuracy accuracy); 54 | } 55 | 56 | 57 | 58 | // Class for running a Quantum Espresso job 59 | class Espresso::Job 60 | { 61 | 62 | // Control variables 63 | bool _saveFiles; 64 | Word _executable; 65 | Word _potDirectory; 66 | Calculation _calculation; 67 | Accuracy _accuracy; 68 | Material _material; 69 | OList _elements; 70 | OList _potentials; 71 | 72 | // Variables to store results 73 | bool _completed; 74 | List _energy; 75 | OList::D2 _forces; 76 | ISO _structure; 77 | 78 | // Static member variables 79 | static Word _dirName; 80 | static Word _inputFileName; 81 | static Word _outputFileName; 82 | 83 | // Functions 84 | void gatherResults(const Basis* basis); 85 | 86 | public: 87 | 88 | // Constructor 89 | Job(); 90 | 91 | // Setup functions 92 | void saveFiles(bool saveFiles) { _saveFiles = saveFiles; } 93 | void executable(const Word& exe) { _executable = exe; } 94 | void potDirectory(const Word& dir) { _potDirectory = dir; } 95 | void calculation(Calculation calculation) { _calculation = calculation; } 96 | void accuracy(Accuracy accuracy) { _accuracy = accuracy; } 97 | void material(Material material) { _material = material; } 98 | void elements(const OList& elements) { _elements = elements; } 99 | void potentials(const OList& potentials) { _potentials = potentials; } 100 | 101 | // Access functions 102 | const Word& executable() const { return _executable; } 103 | const Word& potDirectory() const { return _potDirectory; } 104 | Calculation calculation() const { return _calculation; } 105 | Accuracy accuracy() const { return _accuracy; } 106 | Material material() const { return _material; } 107 | const OList& elements() const { return _elements; } 108 | const OList& potentials() const { return _potentials; } 109 | 110 | // Functions 111 | bool submit(const ISO& iso, bool quitIfError = true); 112 | 113 | // Access functions 114 | bool completed() const { return _completed; } 115 | const List& energy() const { return _energy; } 116 | const OList::D2& forces() const { return _forces; } 117 | void updateStructure(ISO& iso) const; 118 | }; 119 | 120 | 121 | 122 | // Class for reading and writing Quantum Espresso files 123 | class Espresso::Files 124 | { 125 | 126 | // Keywords 127 | enum Keyword {EK_UNKNOWN, EK_CONTROL, EK_SYSTEM, EK_ELECTRONS, EK_IONS, EK_CELL, EK_SPECIES, EK_POSITIONS, \ 128 | EK_KPOINTS, EK_PARAMETERS, EK_CONSTRAINTS, EK_OCCUPATIONS}; 129 | 130 | // Lattice description types 131 | enum ValueType {VT_ALAT, VT_BOHR, VT_ANGSTROM, VT_CRYSTAL}; 132 | 133 | // Functions 134 | static Keyword keyword(const Word& word); 135 | 136 | // Helper functions 137 | static bool isComment(const Word& word) { return (word[0] == '!'); } 138 | static void setBasis(ISO& iso, double A, double B, double C, double cosAB, double cosAC, double cosBC, \ 139 | bool showOutput); 140 | static void setBasis(ISO& iso, double m11, double m12, double m13, double m21, double m22, double m23, \ 141 | double m31, double m32, double m33, bool showOutput); 142 | 143 | public: 144 | 145 | // Read structure 146 | static ISO read(Text content, bool readAsInput = true, const Basis* basis = 0); 147 | static ISO read(const Word& file, bool readAsInput = true, const Basis* basis = 0) 148 | { return read(Read::text(file), readAsInput, basis); } 149 | 150 | // Write structure 151 | static void write(const Word& file, const ISO& iso, CoordinateType coordinates, Job* job = 0, \ 152 | KPoints* kpoints = 0); 153 | 154 | // Check if file is in correct format 155 | static bool isFormat(const Word& file) { return isFormat(Read::text(file)); } 156 | static bool isFormat(const Text& content); 157 | }; 158 | 159 | 160 | 161 | // ===================================================================================================================== 162 | // Job 163 | // ===================================================================================================================== 164 | 165 | /* inline Espresso::Job::Job() 166 | * 167 | * Constructor for quantum espresso job 168 | */ 169 | 170 | inline Espresso::Job::Job() 171 | { 172 | _saveFiles = false; 173 | _calculation = EC_SINGLE; 174 | _accuracy = EA_NORMAL; 175 | _material = EM_METAL; 176 | _completed = false; 177 | } 178 | 179 | 180 | 181 | // ===================================================================================================================== 182 | // Files 183 | // ===================================================================================================================== 184 | 185 | /* inline void Espresso::Files::setBasis(ISO& iso, double A, double B, double C, double cosAB, double cosAC, 186 | * double cosBC, bool showOutput) 187 | * 188 | * Set metric values for basis 189 | */ 190 | 191 | inline void Espresso::Files::setBasis(ISO& iso, double A, double B, double C, double cosAB, double cosAC, \ 192 | double cosBC, bool showOutput) 193 | { 194 | iso.basis(Vector3D(A, B, C), Vector3D(acos(cosBC), acos(cosAC), acos(cosAB)), showOutput); 195 | } 196 | 197 | 198 | 199 | /* inline void Espresso::Files::setBasis(ISO& iso, double m11, double m12, double m13, double m21, double m22, 200 | * double m23, double m31, double m32, double m33, bool showOutput) 201 | * 202 | * Set vector values for basis 203 | */ 204 | 205 | inline void Espresso::Files::setBasis(ISO& iso, double m11, double m12, double m13, double m21, double m22, \ 206 | double m23, double m31, double m32, double m33, bool showOutput) 207 | { 208 | iso.basis(Matrix3D(m11, m12, m13, m21, m22, m23, m31, m32, m33), showOutput); 209 | } 210 | 211 | 212 | 213 | #endif 214 | -------------------------------------------------------------------------------- /src/ewald.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef EWALD_H 24 | #define EWALD_H 25 | 26 | 27 | 28 | #include "locPotential.h" 29 | #include "iso.h" 30 | #include "elements.h" 31 | #include "symmetry.h" 32 | #include "text.h" 33 | #include "constants.h" 34 | #include 35 | 36 | 37 | 38 | /** 39 | * Potential that calculates the Ewald energy of a structure. 40 | * 41 | * For a review of Ewald summation, see: http://protomol.sourceforge.net/ewald.pdf 42 | */ 43 | class Ewald : public SingleLocalPotential { 44 | 45 | protected: 46 | // Set Ewald options 47 | void setEwaldOptions(const Text& input, bool forgiving); 48 | 49 | // Elements and charges 50 | List _charges; 51 | OList _elements; 52 | 53 | // General variables 54 | double _perm; 55 | double _accuracy; 56 | 57 | // Helper variables 58 | // Mixing parameter between short/long range terms 59 | mutable double _alpha; 60 | mutable ImageIterator _realIterator; 61 | // For each recipVector, 1/(e_0*V*|k|^2) * exp(-|k|^2/4/alpha^2) 62 | mutable List _recipFactors; 63 | mutable Linked _recipVectors; 64 | 65 | // Functions 66 | void initialize(const ISO& iso, int numUniqueAtoms) const; 67 | double realEnergy(const ISO& iso, Atom* atom, bool skipLowerAtoms) const; 68 | Vector3D realForce(const ISO& iso, Atom* atom) const; 69 | double recipEnergy(const ISO& iso) const; 70 | Vector3D recipForce(const ISO& iso, Atom* atom) const; 71 | void computeForces(const ISO& iso, OList* totalForces) const; 72 | double selfEnergy(const ISO& iso) const; 73 | double chargedEnergy(const ISO& iso) const; 74 | double realEnergy(double distance) const { return erfc(_alpha * distance) / distance; } 75 | 76 | // Helper functions 77 | double getCharge(const Element& element) const; 78 | 79 | public: 80 | 81 | // Constructor 82 | Ewald() { _perm = Constants::eps0; _accuracy = 1e-8; } 83 | 84 | // Setup by file input 85 | void set(const Text& input); 86 | 87 | // Evaluation functions 88 | void evaluate(const ISO& iso, double* totalEnergy, OList* totalForces) const; 89 | void evaluate(const ISO& iso, const Symmetry& symmetry, double* totalEnergy, \ 90 | OList* totalForces) const; 91 | }; 92 | 93 | 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /src/extPotential.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef EXTPOTENTIAL_H 24 | #define EXTPOTENTIAL_H 25 | 26 | 27 | 28 | #include "vasp.h" 29 | #include "espresso.h" 30 | #include "potential.h" 31 | #include "iso.h" 32 | #include "elements.h" 33 | #include "symmetry.h" 34 | #include "text.h" 35 | #include "num.h" 36 | #include "list.h" 37 | 38 | 39 | 40 | // Vasp potential 41 | class VaspPot : public IPO 42 | { 43 | 44 | // Variables 45 | bool _static; 46 | bool _saveFiles; 47 | Word _executable; 48 | OList _elements; 49 | OList _potentials; 50 | Vasp::Accuracy _accuracy; 51 | OList::D2 _tags; 52 | 53 | public: 54 | 55 | // Constructor 56 | VaspPot() { _saveFiles = false; _accuracy = Vasp::VA_NORMAL; _static = true; } 57 | 58 | // Setup from file 59 | void add(const Text& input, PotentialType type); 60 | 61 | // Static evaluation 62 | void single(const ISO& iso, double* totalEnergy = 0, OList* totalForces = 0, bool restart = false, \ 63 | bool reduce = true) const; 64 | void single(const ISO& iso, const Symmetry& symmetry, double* totalEnergy = 0, OList* totalForces = 0, \ 65 | bool restart = false, bool reduce = true) const { single(iso, totalEnergy, totalForces, restart, reduce); } 66 | 67 | // Relax 68 | void relax(ISO& iso, double* totalEnergy = 0, OList* totalForces = 0, bool restart = false, \ 69 | bool reduce = true) const; 70 | void relax(ISO& iso, const Symmetry& symmetry, double* totalEnergy = 0, OList* totalForces = 0, \ 71 | bool restart = false, bool reduce = true) const { relax(iso, totalEnergy, totalForces, restart, reduce); } 72 | 73 | // NEB 74 | void neb(OList& isos, double* tsEnergy = 0, ISO* tsISO = 0) const; 75 | 76 | // Other functions 77 | bool usesSymmetry() const { return false; } 78 | bool supportsNEB() const { return true; } 79 | }; 80 | 81 | 82 | 83 | // Quantum espresso potential 84 | class QEPot : public IPO 85 | { 86 | 87 | // Variables 88 | bool _static; 89 | bool _saveFiles; 90 | Word _executable; 91 | Word _potDirectory; 92 | OList _elements; 93 | OList _potentials; 94 | Espresso::Accuracy _accuracy; 95 | 96 | public: 97 | 98 | // Constructor 99 | QEPot() { _saveFiles = false; _accuracy = Espresso::EA_NORMAL; _static = true; } 100 | 101 | // Setup from file 102 | void add(const Text& input, PotentialType type); 103 | 104 | // Static evaluation 105 | void single(const ISO& iso, double* energy = 0, OList* totalForces = 0, bool restart = false, \ 106 | bool reduce = true) const; 107 | void single(const ISO& iso, const Symmetry& symmetry, double* totalEnergy = 0, OList* totalForces = 0, \ 108 | bool restart = false, bool reduce = true) const { single(iso, totalEnergy, totalForces, restart, reduce); } 109 | 110 | // Relax 111 | void relax(ISO& iso, double* totalEnergy = 0, OList* totalForces = 0, bool restart = false, \ 112 | bool reduce = true) const; 113 | void relax(ISO& iso, const Symmetry& symmetry, double* totalEnergy = 0, OList* totalForces = 0, \ 114 | bool restart = false, bool reduce = true) const { relax(iso, totalEnergy, totalForces, restart, reduce); } 115 | 116 | // NEB 117 | void neb(OList& isos, double* tsEnergy = 0, ISO* tsISO = 0) const; 118 | 119 | // Other functions 120 | bool usesSymmetry() const { return false; } 121 | bool supportsNEB() const { return false; } 122 | }; 123 | 124 | 125 | 126 | // Class to convert structure to reduced primitive cell before external potential call 127 | class ReduceISO 128 | { 129 | 130 | // Variables 131 | Matrix3D _cellConversion; 132 | Matrix3D _positionConversion; 133 | List::D2 _atomMap; 134 | OList::D2 _translations; 135 | 136 | public: 137 | 138 | // Functions 139 | double reduce(ISO& primISO, const ISO& unitISO, double tol, bool reduce); 140 | void expand(ISO& unitISO, const ISO& primISO); 141 | void expandForces(OList& totalForces, OList primForces, \ 142 | const ISO& unitISO, const ISO& primISO); 143 | }; 144 | 145 | 146 | 147 | /* inline void QEPot::neb(OList& isos, double* tsEnergy, ISO* tsISO) const 148 | * 149 | * NEB calculation 150 | */ 151 | 152 | inline void QEPot::neb(OList& isos, double* tsEnergy, ISO* tsISO) const 153 | { 154 | if (tsEnergy) 155 | *tsEnergy = 0; 156 | if (tsISO) 157 | tsISO->clear(); 158 | } 159 | 160 | 161 | 162 | #endif 163 | -------------------------------------------------------------------------------- /src/fileSystem.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef FILESYSTEM_H 24 | #define FILESYSTEM_H 25 | 26 | 27 | 28 | #include "text.h" 29 | 30 | 31 | 32 | // Namespace for functions to read from file 33 | namespace Read 34 | { 35 | Text text(const Word& file); 36 | } 37 | 38 | 39 | 40 | // Namespace for file functions 41 | namespace File 42 | { 43 | void copy(const Word& from, const Word& to); 44 | bool exists(const Word& file, bool exitIfNotFound = false); 45 | void create(const Word& file, bool clearIfExists = true); 46 | void remove(const Word& file); 47 | } 48 | 49 | 50 | 51 | // Namespace for directory functions 52 | namespace Directory 53 | { 54 | char* home(); 55 | bool exists(const Word& path); 56 | void create(const Word& path, bool deleteIfExists); 57 | void remove(const Word& path); 58 | void recurseRemove(const Word& path); 59 | bool current(Word& path); 60 | Word makePath(const Word& base, const Word& append); 61 | void change(const Word& newDir); 62 | } 63 | 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/findsym.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #include "findsym.h" 24 | #include "num.h" 25 | #include "output.h" 26 | 27 | 28 | 29 | /* void FindSym::write(const Word& file, const ISO& iso, double tol) 30 | * 31 | * Write structure to findsym file 32 | */ 33 | 34 | void FindSym::write(const Word& file, const ISO& iso, double tol) 35 | { 36 | 37 | // Precision for printing numbers 38 | int prec = 14; 39 | 40 | // Setup output if file was set 41 | int origStream = Output::streamID(); 42 | PrintMethod origMethod = Output::method(); 43 | if (file.length() > 0) 44 | { 45 | 46 | // Open file for writing if needed 47 | if (file != "stdout") 48 | Output::setStream(Output::addStream(file)); 49 | 50 | // Set output method 51 | Output::method(STANDARD); 52 | } 53 | 54 | // Write elements on comment line 55 | int i; 56 | Output::newline(); 57 | for (i = 0; i < iso.atoms().length(); ++i) 58 | { 59 | Output::print(iso.atoms()[i][0].element().symbol()); 60 | Output::print(" "); 61 | } 62 | 63 | // Write tolerance 64 | Output::newline(); 65 | Output::printSci(tol); 66 | 67 | // Print lattice parameters 68 | Output::newline(); 69 | Output::print("2"); 70 | Output::newline(); 71 | for (i = 0; i < 3; ++i) 72 | { 73 | Output::print(iso.basis().lengths()[i]); 74 | Output::print(" "); 75 | } 76 | for (i = 0; i < 3; ++i) 77 | { 78 | Output::print(Num::toDegrees(iso.basis().angles()[i])); 79 | Output::print(" "); 80 | } 81 | 82 | // Write form for lattice vectors 83 | Output::newline(); 84 | Output::print("2"); 85 | Output::newline(); 86 | Output::print("P"); 87 | 88 | // Print number of atoms 89 | Output::newline(); 90 | Output::print(iso.numAtoms()); 91 | 92 | // Print type of each atom 93 | int j; 94 | Output::newline(); 95 | for (i = 0; i < iso.atoms().length(); ++i) 96 | { 97 | for (j = 0; j < iso.atoms()[i].length(); ++j) 98 | { 99 | Output::print(i + 1); 100 | Output::print(" "); 101 | } 102 | } 103 | 104 | // Make list of atom positions 105 | int k; 106 | Output message; 107 | message.addLines(iso.numAtoms()); 108 | for (i = 0; i < iso.atoms().length(); ++i) 109 | { 110 | for (j = 0; j < iso.atoms()[i].length(); ++j) 111 | { 112 | message.addLine(); 113 | for (k = 0; k < 3; ++k) 114 | message.add(iso.atoms()[i][j].fractional()[k], prec); 115 | } 116 | } 117 | 118 | // Print coordinates 119 | Output::newline(); 120 | Output::print(message, RIGHT); 121 | 122 | // Reset output if file was set 123 | if (file.length() > 0) 124 | { 125 | if (file != "stdout") 126 | Output::removeStream(Output::streamID()); 127 | Output::setStream(origStream); 128 | Output::method(origMethod); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/findsym.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef FINDSYM_H 24 | #define FINDSYM_H 25 | 26 | 27 | 28 | #include "iso.h" 29 | #include "text.h" 30 | 31 | 32 | 33 | // FindSym structure functions 34 | class FindSym 35 | { 36 | public: 37 | static void write(const Word& file, const ISO& iso, double tol); 38 | }; 39 | 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/gaPredict.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef GAPREDICT_H 24 | #define GAPREDICT_H 25 | 26 | 27 | 28 | #include "ga.h" 29 | #include "iso.h" 30 | #include "symmetry.h" 31 | #include "potential.h" 32 | #include "diffraction.h" 33 | #include "random.h" 34 | #include "text.h" 35 | #include "list.h" 36 | 37 | 38 | 39 | // Fitness metrics 40 | enum GAPredictMetric {GAPM_UNKNOWN, GAPM_POTENTIAL, GAPM_DIFFRACTION}; 41 | 42 | 43 | 44 | // Class to store structure and symmetry pair 45 | class ISOSymmetryPair 46 | { 47 | 48 | // Variables 49 | ISO _iso; 50 | Symmetry _symmetry; 51 | 52 | public: 53 | 54 | // Functions 55 | ISOSymmetryPair& operator= (const ISOSymmetryPair& rhs); 56 | 57 | // Access functions 58 | ISO& iso() { return _iso; } 59 | Symmetry& symmetry() { return _symmetry; } 60 | }; 61 | 62 | 63 | 64 | // Class to run a genetic algorithm structure prediction 65 | class GAPredict 66 | { 67 | 68 | // Settings 69 | int _numScreens; 70 | int _numSimulations; 71 | int _maxCrossoverLoops; 72 | double _minBondFraction; 73 | double _wyckoffBias; 74 | double _cellMutationProb; 75 | double _posMutationProb; 76 | double _wyckMutationProb; 77 | double _energyTolerance; 78 | double _diffractionTolerance; 79 | bool _userietveld; 80 | bool _saveAllResults; // Whether to print out each candidate structure 81 | GAPredictMetric _optMetric; 82 | GAPredictMetric _screenMetric; 83 | 84 | // Variables 85 | GeneticAlgorithm _ga; 86 | List _metrics; 87 | 88 | // Storage 89 | Potential* _potential; 90 | CalculatedPattern* _diffraction; 91 | Diffraction* _refDiffraction; 92 | 93 | // Functions 94 | void printFitness(int generation); 95 | 96 | // Mutation functions 97 | void mutateBasis(ISOSymmetryPair& pair, Random& random); 98 | void mutatePositions(ISOSymmetryPair& pair, Random& random); 99 | void mutateWyckoff(ISOSymmetryPair& pair, Random& random); 100 | 101 | // Crossover functions 102 | void crossover(ISOSymmetryPair& pair, int mother, int father, Random& random); 103 | List::D2 getFixedOrbits(int mother, int father); 104 | List::D3 groupOrbits(int mother, int father, const List::D2& fixedOrbits); 105 | void getOrbitCombinations(Linked >& allowedGroups, const List::D2 orbitGroups, int numToAdd); 106 | void recurseOrbits(Linked >& allowedGroups, const List& lengths, const List& mults, \ 107 | const List& curList, int curGroup, int numToAdd); 108 | 109 | // Screen functions 110 | double screen(ISOSymmetryPair& pair); 111 | 112 | void saveResult(int entry); 113 | 114 | public: 115 | 116 | // Constructor 117 | GAPredict(); 118 | 119 | // General settings functions 120 | void numScreens(int input) { _numScreens = input; } 121 | void numSimulations(int input) { _numSimulations = input; } 122 | void maxCrossoverLoops(int input) { _maxCrossoverLoops = input; } 123 | void minBondFraction(double input) { _minBondFraction = input; } 124 | void wyckoffBias(double input) { _wyckoffBias = input; } 125 | void cellMutationProbability(double input) { _cellMutationProb = input; } 126 | void positionMutationProbability(double input) { _posMutationProb = input; } 127 | void wyckoffMutationProbability(double input) { _wyckMutationProb = input; } 128 | void metricToOptimize(GAPredictMetric input) { _optMetric = input; } 129 | void metricToScreen(GAPredictMetric input) { _screenMetric = input; } 130 | void energyTolerance(double input) { _energyTolerance = input; } 131 | void diffractionTolerance(double input) { _diffractionTolerance = input; } 132 | void useRietveld(bool input) { _userietveld = input; } 133 | /** 134 | * Set whether to print each candidate structure 135 | * @param input Desired setting 136 | */ 137 | void setSaveAllResults(bool input) { _saveAllResults = input; } 138 | 139 | // GA settings functions 140 | void populationSize(int input) { _ga.populationSize(input); } 141 | void convergeOver(int input) { _ga.convergeOver(input); } 142 | void maxGenerations(int input) { _ga.maxGenerations(input); } 143 | void numToKeep(int input) { _ga.numToKeep(input); } 144 | 145 | // Selection settings functions 146 | void selectionMethod(GASelectionMethod input) { _ga.selection().set(input); } 147 | 148 | // Run functions 149 | void run(ISO& iso, Random& random, bool restartable = false, 150 | Potential* potential = 0, Diffraction* diffraction = 0); 151 | 152 | // Used for restarting old runs 153 | void writeRestartInformation(); 154 | void readRestartInformation(ISO& inputStrc); 155 | 156 | // Static member functions 157 | static GAPredictMetric metric(const Word& input); 158 | static Word metric(GAPredictMetric input); 159 | }; 160 | 161 | 162 | 163 | /* inline GAPredict::GAPredict() 164 | * 165 | * Constructor for GAPredict object 166 | */ 167 | inline GAPredict::GAPredict() { 168 | _numScreens = 0; 169 | _numSimulations = 1; 170 | _maxCrossoverLoops = 100; 171 | _minBondFraction = 0.5; 172 | _wyckoffBias = 0.5; 173 | _cellMutationProb = 0.1; 174 | _posMutationProb = 0.1; 175 | _wyckMutationProb = 0.1; 176 | _optMetric = GAPM_UNKNOWN; 177 | _screenMetric = GAPM_UNKNOWN; 178 | _energyTolerance = 1e-3; 179 | _diffractionTolerance = 1e-4; 180 | _saveAllResults = false; 181 | } 182 | 183 | 184 | 185 | /** 186 | * Return metric from word 187 | * @param input [in] Name of metric to be optimized 188 | * @return Corresponding GAPredictMetric 189 | */ 190 | inline GAPredictMetric GAPredict::metric(const Word& input) { 191 | if ((input.equal("potential", false, 3)) || (input.equal("energy", false, 4))) 192 | return GAPM_POTENTIAL; 193 | if ((input.equal("diffraction", false, 4)) || (input.equal("xray", false))) 194 | return GAPM_DIFFRACTION; 195 | return GAPM_UNKNOWN; 196 | } 197 | 198 | 199 | 200 | /** 201 | * Return word from metric 202 | * @param input [in] GAPredictMetric value 203 | * @return Name of that metric 204 | */ 205 | inline Word GAPredict::metric(GAPredictMetric input) { 206 | switch (input) { 207 | case GAPM_POTENTIAL: 208 | return Word("Energy"); 209 | case GAPM_DIFFRACTION: 210 | return Word("Diffraction match"); 211 | default: 212 | return Word("Unknown"); 213 | } 214 | } 215 | 216 | 217 | 218 | #endif 219 | -------------------------------------------------------------------------------- /src/help.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef MINTHELP_H 24 | #define MINTHELP_H 25 | 26 | 27 | 28 | #include "text.h" 29 | 30 | 31 | 32 | // Class for help functions 33 | class Help 34 | { 35 | 36 | // Functions 37 | static void general(); 38 | static void interface(); 39 | static void functions(); 40 | static void settings(); 41 | 42 | public: 43 | 44 | // Functions 45 | static void run(const Words& args); 46 | }; 47 | 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/interstitial.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef INTERSTITIAL_H 24 | #define INTERSTITIAL_H 25 | 26 | 27 | 28 | #include "iso.h" 29 | #include "symmetry.h" 30 | #include "num.h" 31 | #include "list.h" 32 | 33 | 34 | 35 | // Class to compute interstitial sites 36 | class Interstitial 37 | { 38 | 39 | // Variables to store results 40 | OList _sites; 41 | 42 | // Functions 43 | bool minimizePoint(Vector3D& point, const ISO& iso, double scale); 44 | Vector3D getStep(const ISO& iso, const Vector3D& point, Vector3D& deriv, Matrix3D& hessian, double scale); 45 | 46 | public: 47 | 48 | // Functions 49 | void clear() { _sites.length(0); } 50 | void evaluate(const ISO& iso, const Symmetry& symmetry, int numPointsPerAtom, double tol, double scale = 1.0); 51 | void voronoi(const ISO& iso, const Symmetry& symmetry, double tol); 52 | 53 | // Access functions 54 | const OList& sites() const { return _sites; } 55 | }; 56 | 57 | 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/json.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #include "json.h" 24 | #include "bonds.h" 25 | #include "language.h" 26 | #include "output.h" 27 | #include "list.h" 28 | 29 | 30 | 31 | /* void JSON::write(const Word& file, const ISO& iso) 32 | * 33 | * Write structure to json file 34 | */ 35 | 36 | void JSON::write(const Word& file, const ISO& iso) 37 | { 38 | 39 | // Precision for printing numbers 40 | int prec = 8; 41 | 42 | // Setup output if file was set 43 | int origStream = Output::streamID(); 44 | PrintMethod origMethod = Output::method(); 45 | if (file.length() > 0) 46 | { 47 | 48 | // Open file for writing if needed 49 | if (file != "stdout") 50 | Output::setStream(Output::addStream(file)); 51 | 52 | // Set output method 53 | Output::method(STANDARD); 54 | } 55 | 56 | // Print opening bracket 57 | Output::newline(); 58 | Output::print("{"); 59 | 60 | // Print basis line 61 | Output::newline(); 62 | Output::tab(); 63 | Output::print("\"basis\": ["); 64 | 65 | // Loop over basis vectors to write 66 | int i, j, k; 67 | Words endStrings; 68 | Words startStrings; 69 | Vector3D mults; 70 | Vector3D start; 71 | Output message; 72 | message.addLines(12); 73 | for (i = 0; i < 4; ++i) 74 | { 75 | 76 | // Set starting point for current vertex and directions for each lattice vector 77 | if (i == 0) 78 | { 79 | start = 0.0; 80 | mults.set(1, 1, 1); 81 | } 82 | else if (i == 1) 83 | { 84 | start = iso.basis().vectors()[0]; 85 | start += iso.basis().vectors()[1]; 86 | mults.set(-1, -1, 1); 87 | } 88 | else if (i == 2) 89 | { 90 | start = iso.basis().vectors()[0]; 91 | start += iso.basis().vectors()[2]; 92 | mults.set(-1, 1, -1); 93 | } 94 | else if (i == 3) 95 | { 96 | start = iso.basis().vectors()[1]; 97 | start += iso.basis().vectors()[2]; 98 | mults.set(1, -1, -1); 99 | } 100 | 101 | // Add vectors 102 | startStrings = makeString(start, prec); 103 | for (j = 0; j < 3; ++j) 104 | { 105 | message.addLine(); 106 | message.addTab(); 107 | message.addTab(); 108 | message.add("{"); 109 | message.add("\"start\":"); 110 | message.add("["); 111 | for (k = 0; k < 3; ++k) 112 | message.add(startStrings[k]); 113 | message.add("],"); 114 | message.add("\"end\":"); 115 | message.add("["); 116 | endStrings = makeString(start + Vector3D(iso.basis().vectors()[j]) * mults[j], prec); 117 | for (k = 0; k < 3; ++k) 118 | message.add(endStrings[k]); 119 | message.add("]"); 120 | if ((i == 3) && (j == 2)) 121 | message.add("}"); 122 | else 123 | message.add("},"); 124 | } 125 | } 126 | 127 | // Alignment 128 | List align(16); 129 | align.fill(RIGHT); 130 | align.last() = LEFT; 131 | 132 | // Print vectors 133 | Output::newline(); 134 | Output::print(message, align); 135 | 136 | // Close basis line 137 | Output::newline(); 138 | Output::tab(); 139 | Output::print("],"); 140 | 141 | // Print atoms line 142 | Output::newline(); 143 | Output::tab(); 144 | Output::print("\"atoms\": ["); 145 | 146 | // Set atoms 147 | int m; 148 | Words posStrings; 149 | OList vecsToAdd; 150 | vecsToAdd += Vector3D(0.0); 151 | message.clear(); 152 | message.addLines(iso.numAtoms()); 153 | for (i = 0; i < iso.atoms().length(); ++i) 154 | { 155 | for (j = 0; j < iso.atoms()[i].length(); ++j) 156 | { 157 | 158 | // Get images to add 159 | vecsToAdd.length(1); 160 | if (iso.atoms()[i][j].fractional()[0] < 1e-2) 161 | { 162 | vecsToAdd += Vector3D(1, 0, 0); 163 | if (iso.atoms()[i][j].fractional()[1] < 1e-2) 164 | { 165 | vecsToAdd += Vector3D(1, 1, 0); 166 | if (iso.atoms()[i][j].fractional()[2] < 1e-2) 167 | vecsToAdd += Vector3D(1, 1, 1); 168 | } 169 | if (iso.atoms()[i][j].fractional()[2] < 1e-2) 170 | vecsToAdd += Vector3D(1, 0, 1); 171 | } 172 | if (iso.atoms()[i][j].fractional()[1] < 1e-2) 173 | { 174 | vecsToAdd += Vector3D(0, 1, 0); 175 | if (iso.atoms()[i][j].fractional()[2] < 1e-2) 176 | vecsToAdd += Vector3D(0, 1, 1); 177 | } 178 | if (iso.atoms()[i][j].fractional()[2] < 1e-2) 179 | vecsToAdd += Vector3D(0, 0, 1); 180 | 181 | // Add atoms 182 | for (k = 0; k < vecsToAdd.length(); ++k) 183 | { 184 | message.addLine(); 185 | message.addTab(); 186 | message.addTab(); 187 | message.add("{"); 188 | message.add("\"element\":"); 189 | message.add(Word("\"") + iso.atoms()[i][j].element().symbol() + "\","); 190 | message.add("\"location\":"); 191 | message.add("["); 192 | posStrings = makeString(iso.basis().getCartesian(iso.atoms()[i][j].fractional() + vecsToAdd[k]), prec); 193 | for (m = 0; m < 3; ++m) 194 | message.add(posStrings[m]); 195 | message.add("]"); 196 | if ((i == iso.atoms().length() - 1) && (j == iso.atoms()[i].length() - 1) && \ 197 | (k == vecsToAdd.length() - 1)) 198 | message.add("}"); 199 | else 200 | message.add("},"); 201 | } 202 | } 203 | } 204 | 205 | // Alignment 206 | align.length(12); 207 | align.fill(RIGHT); 208 | align.last() = LEFT; 209 | 210 | // Print atoms 211 | Output::newline(); 212 | Output::print(message, align); 213 | 214 | // Print end of atoms section 215 | Output::newline(); 216 | Output::tab(); 217 | Output::print("],"); 218 | 219 | // Print bonds line 220 | Output::newline(); 221 | Output::tab(); 222 | Output::print("\"bonds\": ["); 223 | 224 | 225 | 226 | // Print end of bonds 227 | Output::newline(); 228 | Output::tab(); 229 | Output::print("]"); 230 | 231 | // Print closing bracket 232 | Output::newline(); 233 | Output::print("}"); 234 | 235 | // Reset output if file was set 236 | if (file.length() > 0) 237 | { 238 | if (file != "stdout") 239 | Output::removeStream(Output::streamID()); 240 | Output::setStream(origStream); 241 | Output::method(origMethod); 242 | } 243 | } 244 | -------------------------------------------------------------------------------- /src/json.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef JSON_H 24 | #define JSON_H 25 | 26 | 27 | 28 | #include "iso.h" 29 | #include "text.h" 30 | #include "num.h" 31 | #include 32 | #include 33 | 34 | 35 | 36 | // JSON structure functions 37 | class JSON 38 | { 39 | static Words makeString(const Vector3D& vector, int prec); 40 | public: 41 | static void write(const Word& file, const ISO& iso); 42 | }; 43 | 44 | 45 | 46 | /* inline Words JSON::makeString(const Vector3D& vector, int prec) 47 | * 48 | * Convert number to string 49 | */ 50 | 51 | inline Words JSON::makeString(const Vector3D& vector, int prec) 52 | { 53 | Words res; 54 | char arg[10]; 55 | char temp[25]; 56 | for (int i = 0; i < 3; ++i) 57 | { 58 | if (i != 2) 59 | sprintf(arg, "%s%d%s", "%.", prec, "f,"); 60 | else 61 | sprintf(arg, "%s%d%s", "%.", prec, "f"); 62 | sprintf(temp, arg, vector[i]); 63 | res += temp; 64 | } 65 | return res; 66 | } 67 | 68 | 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/kpoints.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #include 24 | #include "kpoints.h" 25 | #include "output.h" 26 | 27 | 28 | 29 | // Kpoint densities as points per reciprocal atom 30 | double KPoints::_kppraMetalHigh = 5000; 31 | double KPoints::_kppraMetalNormal = 1000; 32 | double KPoints::_kppraMetalLow = 500; 33 | double KPoints::_kppraInsulatorHigh = 500; 34 | double KPoints::_kppraInsulatorNormal = 100; 35 | double KPoints::_kppraInsulatorLow = 50; 36 | 37 | 38 | 39 | /* void KPoints::mesh(int numAtoms, const Vector3D& lengths, double kppra) 40 | * 41 | * Create mesh 42 | */ 43 | 44 | void KPoints::mesh(int numAtoms, const Vector3D& lengths, double kppra) 45 | { 46 | 47 | // Set the total number of kpoints as # points per reciprocal atom / number of atoms 48 | // Set the average number of kpoints along each direction as cube root of total number of kpoints 49 | double avgKPoints = Num::ceil(pow(kppra / numAtoms, 1.0/3.0)); 50 | 51 | // Get the average lattice vector length 52 | int i; 53 | double avgLength = 0; 54 | for (i = 0; i < 3; i++) 55 | avgLength += lengths[i]; 56 | avgLength /= 3.0; 57 | 58 | // Set the number of kpoints along each direction as average number of kpoints along each direction multiplied 59 | // by the fraction of the average length in reciprocal space 60 | for (i = 0; i < 3; i++) 61 | _mesh[i] = (int) Num::ceil(Num::round(avgKPoints * avgLength / lengths[i], 0.01)); 62 | 63 | // Make sure that none of the kpoints are zero 64 | for (i = 0; i < 3; i++) 65 | _mesh[i] = (_mesh[i] < 1) ? 1 : _mesh[i]; 66 | } 67 | 68 | 69 | 70 | /* void KPoints::write(const Word& file, Format format) const 71 | * 72 | * Write points file 73 | */ 74 | 75 | void KPoints::write(const Word& file, Format format) const 76 | { 77 | 78 | // Open file for writing if needed 79 | int origStream = Output::streamID(); 80 | PrintMethod origMethod = Output::method(); 81 | if (file != "stdout") 82 | Output::setStream(Output::addStream(file)); 83 | 84 | // Set output method 85 | Output::method(STANDARD); 86 | 87 | // Write to correct format 88 | switch (format) 89 | { 90 | case KP_VASP: 91 | writeVasp(); 92 | break; 93 | default: 94 | break; 95 | } 96 | 97 | // Reset output 98 | if (file != "stdout") 99 | Output::removeStream(Output::streamID()); 100 | Output::setStream(origStream); 101 | Output::method(origMethod); 102 | } 103 | 104 | 105 | 106 | /* void KPoints::writeVasp() const 107 | * 108 | * Write kpoints to vasp file 109 | */ 110 | 111 | void KPoints::writeVasp() const 112 | { 113 | 114 | // Print header 115 | Output::newline(); 116 | Output::print("Automatically generated KPOINTS file"); 117 | 118 | // Write automatic 119 | Output::newline(); 120 | Output::print(" 0"); 121 | 122 | // Write centering line 123 | Output::newline(); 124 | if (_centering == KP_MONKHORST) 125 | Output::print("Monkhorst-Pack"); 126 | else 127 | Output::print("Gamma"); 128 | 129 | // Write mesh 130 | Output::newline(); 131 | Output::print(" "); 132 | for (int i = 0; i < 3; ++i) 133 | { 134 | Output::print(_mesh[i]); 135 | Output::print(" "); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/kpoints.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef KPOINTS_H 24 | #define KPOINTS_H 25 | 26 | 27 | 28 | #include "text.h" 29 | #include "num.h" 30 | 31 | 32 | 33 | // Class to store data about kpoints 34 | class KPoints 35 | { 36 | 37 | public: 38 | 39 | // Centering types 40 | enum Centering {KP_GAMMA, KP_MONKHORST}; 41 | 42 | // File formats 43 | enum Format {KP_VASP}; 44 | 45 | private: 46 | 47 | // Variables 48 | int _mesh[3]; 49 | Centering _centering; 50 | 51 | // Functions 52 | void writeVasp() const; 53 | 54 | // Static member variables 55 | static double _kppraMetalHigh; 56 | static double _kppraMetalNormal; 57 | static double _kppraMetalLow; 58 | static double _kppraInsulatorHigh; 59 | static double _kppraInsulatorNormal; 60 | static double _kppraInsulatorLow; 61 | 62 | public: 63 | 64 | // Constructor 65 | KPoints() { _centering = KP_GAMMA; } 66 | 67 | // Functions 68 | void mesh(int numAtoms, const Vector3D& lengths, double kppra); 69 | void mesh(const int* mesh) { _mesh[0] = mesh[0]; _mesh[1] = mesh[1]; _mesh[2] = mesh[2]; } 70 | void centering(Centering centering) { _centering = centering; } 71 | 72 | // Access functions 73 | const int* mesh() const { return _mesh; } 74 | Centering centering() const { return _centering; } 75 | static double kppraMetalHigh() { return _kppraMetalHigh; } 76 | static double kppraMetalNormal() { return _kppraMetalNormal; } 77 | static double kppraMetalLow() { return _kppraMetalLow; } 78 | static double kppraInsulatorHigh() { return _kppraInsulatorHigh; } 79 | static double kppraInsulatorNormal() { return _kppraInsulatorNormal; } 80 | static double kppraInsulatorLow() { return _kppraInsulatorLow; } 81 | 82 | // Write functions 83 | void write(const Word& file, Format format) const; 84 | }; 85 | 86 | 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src/language.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #include "language.h" 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | 30 | /* bool Language::isNumber(const Word& input, bool allowFraction) 31 | * 32 | * Return if word is any number 33 | */ 34 | 35 | bool Language::isNumber(const Word& input, bool allowFraction) 36 | { 37 | 38 | // String is empty 39 | if (!input.length()) 40 | return false; 41 | 42 | // Check word 43 | bool foundNumber = false; 44 | for (int i = 0; i < input.length(); ++i) 45 | { 46 | 47 | // Found a number 48 | if ((input[i] == '0') || (input[i] == '1') || (input[i] == '2') || (input[i] == '3') || (input[i] == '4') || \ 49 | (input[i] == '5') || (input[i] == '6') || (input[i] == '7') || (input[i] == '8') || (input[i] == '9')) 50 | foundNumber = true; 51 | 52 | // Found something else that could be in a number 53 | else if ((input[i] == '.') || (input[i] == 'e') || (input[i] == 'E') || (input[i] == 'd') || \ 54 | (input[i] == 'D') || (input[i] == '+') || (input[i] == '-') || ((input[i] == '/') && (allowFraction))) 55 | continue; 56 | 57 | // Found something else 58 | else 59 | return false; 60 | } 61 | 62 | // Did whether a number was found 63 | return foundNumber; 64 | } 65 | 66 | 67 | 68 | /* bool Language::isInteger(const Word& input) 69 | * 70 | * Return if word is an integer 71 | */ 72 | 73 | bool Language::isInteger(const Word& input) 74 | { 75 | 76 | // Check if a number 77 | if (!isNumber(input)) 78 | return false; 79 | 80 | // Check for a . 81 | for (int i = 0; i < input.length(); ++i) 82 | { 83 | if (input[i] == '.') 84 | return false; 85 | } 86 | 87 | // Found an integer if at this point 88 | return true; 89 | } 90 | 91 | 92 | 93 | /* bool Language::isDecimal(const Word& input) 94 | * 95 | * Return if word is a decimal number 96 | */ 97 | 98 | bool Language::isDecimal(const Word& input) 99 | { 100 | 101 | // Check if a number 102 | if (!isNumber(input)) 103 | return false; 104 | 105 | // Check for a . 106 | for (int i = 0; i < input.length(); ++i) 107 | { 108 | if (input[i] == '.') 109 | return true; 110 | } 111 | 112 | // Did not find a decimal if at this point 113 | return false; 114 | } 115 | 116 | 117 | 118 | /* bool Language::isComment(const Word& input) 119 | * 120 | * Return TRUE if a comment and FALSE otherwise 121 | */ 122 | 123 | bool Language::isComment(const Word& input) 124 | { 125 | if (!input.length()) 126 | return false; 127 | if (input[0] == '#') 128 | return true; 129 | return false; 130 | } 131 | 132 | 133 | 134 | /* Word Language::numberToWord(int number) 135 | * 136 | * Convert an integer number to Word object 137 | */ 138 | 139 | Word Language::numberToWord(int number) 140 | { 141 | char buffer[20]; 142 | sprintf(buffer, "%d", number); 143 | return Word(buffer); 144 | } 145 | 146 | 147 | 148 | /* Word Language::numberToFraction(double number, double tol, bool addDot) 149 | * 150 | * Convert a number to fractional representation 151 | */ 152 | 153 | Word Language::numberToFraction(double number, double tol, bool addDot) 154 | { 155 | 156 | // Result 157 | Word res; 158 | 159 | // Add negative if needed 160 | if (number < 0) 161 | res += "-"; 162 | number = fabs(number); 163 | 164 | // Number is very small 165 | if (number < 1e-12) 166 | { 167 | if (addDot) 168 | return "0.0"; 169 | else 170 | return "0"; 171 | return res; 172 | } 173 | 174 | // Number is very large 175 | if (number > 1e14) 176 | { 177 | if (addDot) 178 | res += "99999999999999.0"; 179 | else 180 | res += "99999999999999"; 181 | return res; 182 | } 183 | 184 | // Number is 1 185 | if ((number < 1 + tol) && (number > 1 - tol)) 186 | { 187 | if (addDot) 188 | res += "1.0"; 189 | else 190 | res += "1"; 191 | return res; 192 | } 193 | 194 | // Loop until fraction is found 195 | double temp; 196 | double Z = number; 197 | double denom = 1; 198 | double num = number; 199 | double prevDenom = 0; 200 | if (fabs(Z - (int)Z) > tol/10) 201 | { 202 | do 203 | { 204 | Z = 1.0/(Z - (int)Z); 205 | temp = denom; 206 | denom = denom * (int)Z + prevDenom; 207 | prevDenom = temp; 208 | num = (int)(number * denom + 0.5); 209 | } 210 | while ((fabs(number - num/denom) > tol) && (Z != (int)Z)); 211 | } 212 | 213 | // Save result 214 | char buffer[20]; 215 | if (fabs(fabs(denom) - 1) < tol) 216 | { 217 | if (addDot) 218 | sprintf(buffer, "%d%s", (int)num, ".0"); 219 | else 220 | sprintf(buffer, "%d", (int)num); 221 | } 222 | else 223 | { 224 | if (addDot) 225 | sprintf(buffer, "%d%s%d%s", (int)num, ".0/", (int)denom, ".0"); 226 | else 227 | sprintf(buffer, "%d%s%d", (int)num, "/", (int)denom); 228 | } 229 | res += buffer; 230 | 231 | // Return result 232 | return res; 233 | } 234 | 235 | 236 | 237 | /* double Language::fractionToNumber(const Word& input) 238 | * 239 | * Turn a fraction into number 240 | */ 241 | 242 | double Language::fractionToNumber(const Word& input) 243 | { 244 | 245 | // Get the numerator 246 | int i; 247 | char temp[25]; 248 | for (i = 0; ((input[i] != '/') && (input[i] != '\0')); ++i) 249 | temp[i] = input[i]; 250 | temp[i] = '\0'; 251 | double res = atof(temp); 252 | 253 | // Get the denominator 254 | if (input[i] == '/') 255 | { 256 | int j = 0; 257 | for (++i; input[i] != '\0'; ++i, ++j) 258 | temp[j] = input[i]; 259 | temp[j] = '\0'; 260 | if (j) 261 | res /= atof(temp); 262 | } 263 | 264 | // Return result 265 | return res; 266 | } 267 | -------------------------------------------------------------------------------- /src/language.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef LANGUAGE_H 24 | #define LANGUAGE_H 25 | 26 | 27 | 28 | #include "text.h" 29 | 30 | 31 | 32 | // Namespace with language functions 33 | namespace Language 34 | { 35 | 36 | // Tests 37 | bool isNumber(const Word& input, bool allowFraction = false); 38 | bool isInteger(const Word& input); 39 | bool isDecimal(const Word& input); 40 | bool isComment(const Word& input); 41 | 42 | // Functions 43 | Word numberToWord(int number); 44 | Word numberToFraction(double number, double tol = 1e-4, bool addDot = false); 45 | double fractionToNumber(const Word& input); 46 | } 47 | 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/launcher.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef LAUNCHER_H 24 | #define LAUNCHER_H 25 | 26 | 27 | 28 | #include "iso.h" 29 | #include "structureIO.h" 30 | #include "symmetry.h" 31 | #include "potential.h" 32 | #include "phonons.h" 33 | #include "kmc.h" 34 | #include "diffraction.h" 35 | #include "random.h" 36 | #include "text.h" 37 | #include "list.h" 38 | 39 | 40 | 41 | // Types of runs 42 | enum Keyword {KEY_NONE, KEY_SETTINGS, KEY_HELP, KEY_NUMPROCS, KEY_OUTPUT, KEY_TIME, KEY_TOLERANCE, KEY_PRINT, \ 43 | KEY_NAME, KEY_FIX, KEY_REMOVE, KEY_NEIGHBORS, KEY_SHELLS, KEY_COORDINATION, KEY_REDUCED, KEY_PRIMITIVE, \ 44 | KEY_CONVENTIONAL, KEY_IDEAL, KEY_SHIFT, KEY_TRANSFORM, KEY_ROTATE, KEY_SYMMETRY, KEY_UNIQUE, KEY_EQUIVALENT, \ 45 | KEY_ABOUT, KEY_POINTGROUP, KEY_SPACEGROUP, KEY_REFINE, KEY_ENERGY, KEY_FORCES, KEY_PHONONS, KEY_KMC, \ 46 | KEY_DIFFRACTION, KEY_PERTURB, KEY_RELAX, KEY_OPT, KEY_INTERSTITIAL, KEY_COMPARE}; 47 | 48 | 49 | 50 | // Class to store data during run 51 | class Storage 52 | { 53 | 54 | // Structure variables 55 | int _curID; 56 | List _id; 57 | OList _iso; 58 | List _needsGeneration; 59 | 60 | // Symmetry variables 61 | OList _symmetry; 62 | List _updateSymmetry; 63 | 64 | // Write variables 65 | List _format; 66 | OList _baseName; 67 | OList _history; 68 | 69 | // Other variables 70 | Potential _potential; 71 | Phonons _phonons; 72 | Text _kmc; 73 | ExperimentalPattern _diffraction; 74 | Random _random; 75 | 76 | public: 77 | 78 | // Constructor 79 | Storage() { _curID = 0; } 80 | 81 | // Add/remove structure 82 | void addISO(); 83 | void removeISO(int index); 84 | 85 | // Print functions 86 | void printLabel(int index, int length = -1); 87 | 88 | // Structure access functions 89 | List& id() { return _id; } 90 | OList& iso() { return _iso; } 91 | List& needsGeneration() { return _needsGeneration; } 92 | 93 | // Symmetry access functions 94 | OList& symmetry() { return _symmetry; } 95 | List& updateSymmetry() { return _updateSymmetry; } 96 | 97 | // Write access functions 98 | List& format() { return _format; } 99 | OList& baseName() { return _baseName; } 100 | OList& history() { return _history; } 101 | 102 | // Other access functions 103 | Potential& potential() { return _potential; } 104 | Phonons& phonons() { return _phonons; } 105 | Text& kmc() { return _kmc; } 106 | ExperimentalPattern& diffraction() { return _diffraction; } 107 | Random& random() { return _random; } 108 | }; 109 | 110 | 111 | 112 | // Class to store a single function and its arguments 113 | class Function 114 | { 115 | 116 | // Variables 117 | Keyword _keyword; 118 | Words _arguments; 119 | 120 | public: 121 | 122 | // Setup functions 123 | void keyword(Keyword input) { _keyword = input; } 124 | void addArgument(const Word& input) { _arguments += input; } 125 | void removeArgument(int index) { _arguments.remove(index); } 126 | 127 | // Access functions 128 | Keyword keyword() const { return _keyword; } 129 | const Words& arguments() const { return _arguments; } 130 | }; 131 | 132 | 133 | 134 | // Class to store functions for Mint 135 | class Launcher 136 | { 137 | 138 | // Type definitions 139 | typedef OList Functions; 140 | 141 | // Startup functions 142 | static Words getArguments(int argc, char** argv); 143 | static Functions getFunctions(const Words& arguments); 144 | static Keyword getKeyword(const Word& argument); 145 | static void runSetup(Storage& data, Functions& functions, bool& keepFree); 146 | static void getCommandLineSettings(Functions& functions, bool& keepFree); 147 | static void setupJobSize(Functions& functions); 148 | static void setupOutput(Functions& functions); 149 | static void setupTolerance(Functions& functions); 150 | static void setupTime(Functions& functions); 151 | static void setupPrint(Functions& functions, bool& keepFree); 152 | static void fixCellParams(Storage& data, Functions& functions); 153 | 154 | // General functions 155 | static void output(const Function& function); 156 | static void tolerance(const Function& function); 157 | static void generateStructure(Storage& data, bool keepFree = false); 158 | static void printStructure(Storage& data, const Functions& functions); 159 | 160 | // Change cell 161 | static void removeAtoms(Storage& data, const Function& function); 162 | static void reduced(Storage& data); 163 | static void primitive(Storage& data); 164 | static void conventional(Storage& data); 165 | static void ideal(Storage& data, const Function& function); 166 | static void shift(Storage& data, const Function& function); 167 | static void transform(Storage& data, const Function& function); 168 | static void rotate(Storage& data, const Function& function); 169 | 170 | // Symmetry functions 171 | static void updateSymmetry(Storage& data); 172 | static void symmetry(Storage& data, const Function& function); 173 | static void unique(Storage& data, const Function& function); 174 | static void about(Storage& data, const Function& function); 175 | static void aboutStructure(Storage& data); 176 | static void aboutAtoms(Storage& data, const Function& function); 177 | static void pointGroup(Storage& data, const Function& function); 178 | static void spaceGroup(Storage& data, const Function& function); 179 | static void refine(Storage& data, const Function& function); 180 | 181 | // Potential evaluation functions 182 | static void energy(Storage& data); 183 | static void forces(Storage& data); 184 | static void phonons(Storage& data, const Function& function); 185 | 186 | // Diffusion functions 187 | static void kmc(Storage& data, const Function& function); 188 | 189 | // Characterization functions 190 | static void diffraction(Storage& data, const Function& function); 191 | 192 | // Random structure and perturbation 193 | static void perturb(Storage& data, const Function& function); 194 | 195 | // Optimize functions 196 | static void relax(Storage& data, const Function& function); 197 | static void optimize(Storage& data, const Function& function); 198 | 199 | // Other functions 200 | static void neighbors(Storage& data, const Function& function); 201 | static void shells(Storage& data, const Function& function); 202 | static void coordination(Storage& data, const Function& function); 203 | static void interstitial(Storage& data, const Function& function); 204 | 205 | // Compare two structures 206 | static void compare(Storage& data, const Function& function); 207 | 208 | // Alternate runs 209 | static bool runSettings(const Functions& functions); 210 | static bool runHelp(const Functions& functions); 211 | 212 | // Helper functions 213 | static bool fileNameUsed(const OList& fileNames, const Word& curName, int numToCheck); 214 | static List getAtoms(const ISO& iso, const Function& function, bool allowPositions = true, \ 215 | bool autoPopAll = true); 216 | static void sortAtoms(List& atoms, int left, int right); 217 | 218 | public: 219 | 220 | // Main function 221 | static void start(int argc, char** argv); 222 | }; 223 | 224 | 225 | 226 | #endif 227 | -------------------------------------------------------------------------------- /src/locPotential.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #include "locPotential.h" 24 | #include "pairPotential.h" 25 | #include "ewald.h" 26 | #include "relax.h" 27 | #include "output.h" 28 | #include "electrostatic.h" 29 | 30 | 31 | 32 | /* void SingleLocalPotential::readError(const OList& line) 33 | * 34 | * Error in reading file 35 | */ 36 | 37 | void SingleLocalPotential::readError(const OList& line) 38 | { 39 | Output::newline(ERROR); 40 | Output::print("Did not recognize potential setting on line \""); 41 | for (int i = 0; i < line.length(); ++i) 42 | { 43 | Output::print(line[i]); 44 | if (i != line.length() - 1) 45 | Output::print(" "); 46 | } 47 | Output::print("\""); 48 | Output::quit(); 49 | } 50 | 51 | 52 | 53 | /* void LocalPotential::add(const Text& input, PotentialType type) 54 | * 55 | * Add potential to local potential list 56 | */ 57 | 58 | void LocalPotential::add(const Text& input, PotentialType type) 59 | { 60 | 61 | // Ewald potential 62 | if (type == PT_EWALD) 63 | _potentials += new Ewald; 64 | 65 | // Electrostatic (PEGS) potential 66 | else if (type == PT_ELECTROSTATIC) 67 | _potentials += new Electrostatic; 68 | 69 | // Lennard-Jones potential 70 | else if (type == PT_LENNARDJONES) 71 | _potentials += new LennardJones; 72 | 73 | // Buckingham potential 74 | else if (type == PT_BUCKINGHAM) 75 | _potentials += new Buckingham; 76 | 77 | // Power potential 78 | else if (type == PT_POWER) 79 | _potentials += new Power; 80 | 81 | // Exponential potential 82 | else if (type == PT_EXPONENTIAL) 83 | _potentials += new Exponential; 84 | 85 | // Covalent potential 86 | else if (type == PT_COVALENT) 87 | _potentials += new Covalent; 88 | 89 | // Unknown potential 90 | else 91 | { 92 | Output::newline(ERROR); 93 | Output::print("Internal error in setting local potential"); 94 | Output::quit(); 95 | } 96 | 97 | // Add data for potential 98 | _potentials.last()->set(input); 99 | } 100 | 101 | 102 | 103 | /* void LocalPotential::relax(ISO& iso, double* totalEnergy, OList* totalForces, bool restart, 104 | * bool reduce) const 105 | * 106 | * Relax structure 107 | */ 108 | 109 | void LocalPotential::relax(ISO& iso, double* totalEnergy, OList* totalForces, bool restart, \ 110 | bool reduce) const 111 | { 112 | initialize(iso, totalEnergy, totalForces); 113 | Relax relax; 114 | relax.structure(iso, *this); 115 | if ((totalEnergy) || (totalForces)) 116 | single(iso, totalEnergy, totalForces); 117 | } 118 | 119 | 120 | 121 | /* void LocalPotential::relax(ISO& iso, const Symmetry& symmetry, double* totalEnergy, OList* totalForces, 122 | * bool restart, bool reduce) const 123 | * 124 | * Relax structure 125 | */ 126 | 127 | void LocalPotential::relax(ISO& iso, const Symmetry& symmetry, double* totalEnergy, OList* totalForces, \ 128 | bool restart, bool reduce) const 129 | { 130 | initialize(iso, totalEnergy, totalForces); 131 | Relax relax; 132 | relax.structure(iso, *this, symmetry); 133 | if ((totalEnergy) || (totalForces)) 134 | single(iso, symmetry, totalEnergy, totalForces); 135 | } 136 | -------------------------------------------------------------------------------- /src/locPotential.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef LOCPOTENTIAL_H 24 | #define LOCPOTENTIAL_H 25 | 26 | 27 | 28 | #include "potential.h" 29 | #include "iso.h" 30 | #include "symmetry.h" 31 | #include "text.h" 32 | #include "num.h" 33 | #include "list.h" 34 | 35 | 36 | 37 | // Single local potential 38 | class SingleLocalPotential 39 | { 40 | protected: 41 | 42 | // Functions 43 | void readError(const OList& line); 44 | 45 | public: 46 | 47 | // Virtual functions 48 | virtual ~SingleLocalPotential() {} 49 | virtual void set(const Text& input) = 0; 50 | virtual void evaluate(const ISO& iso, double* energy = 0, OList* forces = 0) const = 0; 51 | virtual void evaluate(const ISO& iso, const Symmetry& symmetry, double* energy = 0, \ 52 | OList* forces = 0) const = 0; 53 | }; 54 | 55 | 56 | 57 | // Local potential 58 | class LocalPotential : public IPO 59 | { 60 | 61 | // Variables 62 | List _potentials; 63 | 64 | // Functions 65 | void initialize(const ISO& iso, double* energy, OList* forces) const; 66 | 67 | public: 68 | 69 | // Destructor 70 | ~LocalPotential(); 71 | 72 | // Setup from file 73 | void add(const Text& input, PotentialType type); 74 | 75 | // Static evaluation 76 | void single(const ISO& iso, double* totalEnergy = 0, OList* totalForces = 0, bool restart = false, \ 77 | bool reduce = true) const; 78 | void single(const ISO& iso, const Symmetry& symmetry, double* totalEnergy = 0, OList* totalForces = 0, \ 79 | bool restart = false, bool reduce = true) const; 80 | 81 | // Relax 82 | void relax(ISO& iso, double* totalEnergy = 0, OList* totalForces = 0, bool restart = false, \ 83 | bool reduce = true) const; 84 | void relax(ISO& iso, const Symmetry& symmetry, double* totalEnergy = 0, OList* totalForces = 0, \ 85 | bool restart = false, bool reduce = true) const; 86 | 87 | // NEB 88 | void neb(OList& isos, double* tsEnergy = 0, ISO* tsISO = 0) const; 89 | 90 | // Other functions 91 | bool usesSymmetry() const { return true; } 92 | bool supportsNEB() const { return false; } 93 | }; 94 | 95 | 96 | 97 | /* inline LocalPotential::~LocalPotential() 98 | * 99 | * Destructor for local potential object 100 | */ 101 | 102 | inline LocalPotential::~LocalPotential() 103 | { 104 | for (int i = 0; i < _potentials.length(); ++i) 105 | delete _potentials[i]; 106 | } 107 | 108 | 109 | 110 | /* inline void LocalPotential::initialize(const ISO& iso, double* energy, OList* forces) const 111 | * 112 | * Initialize variables for evaluation 113 | */ 114 | 115 | inline void LocalPotential::initialize(const ISO& iso, double* energy, OList* forces) const 116 | { 117 | if (energy) 118 | *energy = 0; 119 | if (forces) 120 | { 121 | forces->length(iso.numAtoms()); 122 | forces->fill(0.0); 123 | } 124 | } 125 | 126 | 127 | 128 | /* inline void LocalPotential::single(const ISO& iso, double* totalEnergy, OList* totalForces, 129 | * bool restart, bool reduce) const 130 | * 131 | * Calculate energy and forces of structure 132 | */ 133 | 134 | inline void LocalPotential::single(const ISO& iso, double* totalEnergy, OList* totalForces, \ 135 | bool restart, bool reduce) const 136 | { 137 | initialize(iso, totalEnergy, totalForces); 138 | for (int i = 0; i < _potentials.length(); ++i) 139 | _potentials[i]->evaluate(iso, totalEnergy, totalForces); 140 | } 141 | 142 | 143 | 144 | /* inline void LocalPotential::single(const ISO& iso, const Symmetry& symmetry, double* totalEnergy, 145 | * OList* totalForces, bool restart, bool reduce) const 146 | * 147 | * Calculate energy and forces of structure 148 | */ 149 | 150 | inline void LocalPotential::single(const ISO& iso, const Symmetry& symmetry, double* totalEnergy, \ 151 | OList* totalForces, bool restart, bool reduce) const 152 | { 153 | initialize(iso, totalEnergy, totalForces); 154 | for (int i = 0; i < _potentials.length(); ++i) 155 | _potentials[i]->evaluate(iso, symmetry, totalEnergy, totalForces); 156 | } 157 | 158 | 159 | 160 | /* inline void LocalPotential::neb(OList& isos, double* tsEnergy, ISO* tsISO) const 161 | * 162 | * NEB calculation 163 | */ 164 | 165 | inline void LocalPotential::neb(OList& isos, double* tsEnergy, ISO* tsISO) const 166 | { 167 | if (tsEnergy) 168 | *tsEnergy = 0; 169 | if (tsISO) 170 | tsISO->clear(); 171 | } 172 | 173 | 174 | 175 | #endif 176 | -------------------------------------------------------------------------------- /src/mint.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #include "multi.h" 24 | #include "output.h" 25 | #include "launcher.h" 26 | 27 | 28 | 29 | // Main function 30 | int main(int argc, char** argv) 31 | { 32 | 33 | // Start MPI 34 | Multi::initialize(argc, argv); 35 | 36 | // Start output 37 | Output::initialize(); 38 | 39 | // Call launcher to process arguments and call functions 40 | Launcher::start(argc, argv); 41 | 42 | // Close MPI 43 | Multi::finalize(); 44 | 45 | // Finished 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /src/mintStructure.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef MINTSTRUCTURE_H 24 | #define MINTSTRUCTURE_H 25 | 26 | 27 | 28 | #include "iso.h" 29 | #include "text.h" 30 | #include "fileSystem.h" 31 | 32 | 33 | 34 | // Mint structure functions 35 | class MintStructure 36 | { 37 | 38 | // Labels 39 | enum Label {UNKNOWN, SPACEGROUP, BASIS, ELEMENT, FRACPOS, CARTPOS, FIXED, MULTIPLICITY, EXPAND, INTERSTITIAL}; 40 | 41 | // Functions 42 | static Label getLabel(const Word& word); 43 | static void addAtom(ISO& iso, const Element& element, const Vector3D& position, bool useFractional, \ 44 | bool setFixed, const bool* fixed, bool interstitial); 45 | 46 | public: 47 | 48 | // Functions 49 | static ISO read(const Text& content, double tol, double clusterTol); 50 | static ISO read(const Word& file, double tol, double clusterTol) 51 | { return read(Read::text(file), tol, clusterTol); } 52 | static void write(const Word& file, const ISO& iso, CoordinateType coordinates); 53 | static bool isFormat(const Word& file) { return isFormat(Read::text(file)); } 54 | static bool isFormat(const Text& content); 55 | }; 56 | 57 | 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/multi.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifdef MINT_MPI 24 | #include 25 | #endif 26 | #include "multi.h" 27 | #include "language.h" 28 | #include 29 | #include 30 | #include 31 | using namespace std; 32 | 33 | 34 | 35 | // Initialize static variables 36 | int Multi::_rank = 0; 37 | int Multi::_worldSize = 1; 38 | #ifdef MINT_MPI 39 | bool Multi::_mpiOn = true; 40 | #else 41 | bool Multi::_mpiOn = false; 42 | #endif 43 | bool Multi::_setExitFun = false; 44 | bool Multi::_runningFun = false; 45 | int Multi::_jobSize = 1; 46 | 47 | 48 | 49 | /* void Multi::initialize(int argc, char** argv) 50 | * 51 | * Initialize MPI functionality 52 | */ 53 | 54 | void Multi::initialize(int argc, char** argv) 55 | { 56 | #ifdef MINT_MPI 57 | 58 | // Start MPI 59 | MPI_Init(&argc, &argv); 60 | 61 | // Get the rank and number of processors 62 | MPI_Comm_rank(MPI_COMM_WORLD, &_rank); 63 | MPI_Comm_size(MPI_COMM_WORLD, &_worldSize); 64 | 65 | #endif 66 | } 67 | 68 | 69 | 70 | /* void Multi::finalize() 71 | * 72 | * End MPI functionality 73 | */ 74 | 75 | void Multi::finalize() 76 | { 77 | #ifdef MINT_MPI 78 | 79 | // Close MPI 80 | MPI_Finalize(); 81 | 82 | #endif 83 | } 84 | 85 | 86 | 87 | /* bool Multi::safeCall(void (&function)(), const char* stdoutFile, const char* stderrFile) 88 | * 89 | * Call a function and avoid premature exit 90 | */ 91 | 92 | bool Multi::safeCall(void (&function)(), const char* stdoutFile, const char* stderrFile) 93 | { 94 | 95 | // Set atexit function if needed 96 | if (!_setExitFun) 97 | { 98 | atexit(exitfun); 99 | _setExitFun = true; 100 | } 101 | 102 | // Redirect stdout if needed 103 | int out; 104 | if (stdoutFile) 105 | { 106 | out = dup(fileno(stdout)); 107 | freopen(stdoutFile, "w", stdout); 108 | } 109 | 110 | // Redirect stderr if needed 111 | int err; 112 | if (stderrFile) 113 | { 114 | err = dup(fileno(stderr)); 115 | freopen(stderrFile, "w", stderr); 116 | } 117 | 118 | // Call function 119 | bool ranWithoutError = true; 120 | _runningFun = true; 121 | try { function(); } 122 | catch (...) { ranWithoutError = false; } 123 | _runningFun = false; 124 | 125 | // Reset stdout if needed 126 | if (stdoutFile) 127 | { 128 | fflush(stdout); 129 | dup2(out, fileno(stdout)); 130 | close(out); 131 | } 132 | 133 | // Reset stderr if needed 134 | if (stderrFile) 135 | { 136 | fflush(stderr); 137 | dup2(err, fileno(stderr)); 138 | close(err); 139 | } 140 | 141 | // Return result 142 | return ranWithoutError; 143 | } 144 | 145 | 146 | 147 | /* void Multi::external(const Word& exe, const char* flags, const char* stdoutFile) 148 | * 149 | * Run external program 150 | */ 151 | 152 | void Multi::external(const Word& exe, const char* flags, const char* stdoutFile) 153 | { 154 | 155 | // Set mpirun command 156 | Word mpirun; 157 | 158 | // Only run if there is more than one processor 159 | if (_jobSize > 1) 160 | { 161 | 162 | // Save mpirun call 163 | #ifdef MPIRUN 164 | mpirun = MPIRUN; 165 | #endif 166 | 167 | // Look for -np 168 | int i; 169 | if (mpirun.contains("-np", false)) 170 | { 171 | for (i = 0; i < mpirun.length() - 2; ++i) 172 | { 173 | if ((mpirun[i] == '-') && ((mpirun[i+1] == 'n') || (mpirun[i+1] == 'N')) && \ 174 | ((mpirun[i+2] == 'p') || (mpirun[i+2] == 'P'))) 175 | { 176 | mpirun.insert(" ", i+3); 177 | mpirun.insert(Language::numberToWord(_jobSize), i+4); 178 | } 179 | } 180 | } 181 | 182 | // Look for -n 183 | else if (mpirun.contains("-n", false)) 184 | { 185 | for (i = 0; i < mpirun.length() - 1; ++i) 186 | { 187 | if ((mpirun[i] == '-') && ((mpirun[i+1] == 'n') || (mpirun[i+1] == 'N'))) 188 | { 189 | mpirun.insert(" ", i+2); 190 | mpirun.insert(Language::numberToWord(_jobSize), i+3); 191 | } 192 | } 193 | } 194 | } 195 | 196 | // Add executable name 197 | if (mpirun.length() > 0) 198 | mpirun += " "; 199 | mpirun += exe; 200 | 201 | // Add flags 202 | if (flags) 203 | { 204 | mpirun += " "; 205 | mpirun += flags; 206 | } 207 | 208 | // Add output redirect 209 | if (stdoutFile) 210 | { 211 | mpirun += " &> "; 212 | mpirun += stdoutFile; 213 | } 214 | 215 | // Add wait 216 | mpirun += "; wait"; 217 | 218 | // Call job for root only 219 | if (!_rank) 220 | system(mpirun.array()); 221 | barrier(); 222 | } 223 | -------------------------------------------------------------------------------- /src/multi.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef MULTI_H 24 | #define MULTI_H 25 | 26 | 27 | 28 | #ifdef MINT_MPI 29 | #include 30 | #endif 31 | #include "text.h" 32 | #include "num.h" 33 | 34 | 35 | 36 | // Class for MPI functions 37 | class Multi 38 | { 39 | 40 | // Variables 41 | static int _rank; 42 | static int _worldSize; 43 | static bool _mpiOn; 44 | 45 | // Variables to control job 46 | static bool _setExitFun; 47 | static bool _runningFun; 48 | static int _jobSize; 49 | 50 | // Exit function to control jobs 51 | static void exitfun() { if (_runningFun) throw 1; } 52 | 53 | public: 54 | 55 | // Setup functions 56 | static void initialize(int argc, char** argv); 57 | static void finalize(); 58 | static void jobSize(int input) { _jobSize = input; } 59 | 60 | // General functions 61 | static void barrier(); 62 | static bool safeCall(void (&function)(), const char* stdoutFile = 0, const char* stderrFile = 0); 63 | static void external(const Word& exe, const char* flags = 0, const char* stdoutFile = 0); 64 | 65 | // Send single values 66 | static void send( bool& value, int root, int dest) { send(&value, 1, root, dest); } 67 | static void send( int& value, int root, int dest) { send(&value, 1, root, dest); } 68 | static void send(unsigned long int& value, int root, int dest) { send(&value, 1, root, dest); } 69 | static void send( double& value, int root, int dest) { send(&value, 1, root, dest); } 70 | static void send( char& value, int root, int dest) { send(&value, 1, root, dest); } 71 | 72 | // Send arrays 73 | static void send( bool* array, int length, int root, int dest); 74 | static void send( int* array, int length, int root, int dest); 75 | static void send(unsigned long int* array, int length, int root, int dest); 76 | static void send( double* array, int length, int root, int dest); 77 | static void send( char* array, int length, int root, int dest); 78 | 79 | // Send special values 80 | static void send(Vector3D& vector, int root, int dest); 81 | 82 | // Broadcast single values 83 | static void broadcast( bool& value, int root) { broadcast(&value, 1, root); } 84 | static void broadcast( int& value, int root) { broadcast(&value, 1, root); } 85 | static void broadcast(unsigned long int& value, int root) { broadcast(&value, 1, root); } 86 | static void broadcast( double& value, int root) { broadcast(&value, 1, root); } 87 | static void broadcast( char& value, int root) { broadcast(&value, 1, root); } 88 | 89 | // Broadcast arrays 90 | static void broadcast( bool* array, int length, int root); 91 | static void broadcast( int* array, int length, int root); 92 | static void broadcast(unsigned long int* array, int length, int root); 93 | static void broadcast( double* array, int length, int root); 94 | static void broadcast( char* array, int length, int root); 95 | 96 | // Broadcast special values 97 | static void broadcast(Vector3D& vector, int root); 98 | static void broadcast( Vector& vector, int root); 99 | 100 | // Access functions 101 | static int rank() { return _rank; } 102 | static int worldSize() { return _worldSize; } 103 | static bool mpiOn() { return _mpiOn; } 104 | }; 105 | 106 | 107 | 108 | /* inline void Multi::barrier() 109 | * 110 | * Add barrier 111 | */ 112 | 113 | inline void Multi::barrier() 114 | { 115 | #ifdef MINT_MPI 116 | MPI_Barrier(MPI_COMM_WORLD); 117 | #endif 118 | } 119 | 120 | 121 | 122 | /* inline void Multi::send(TYPE* array, int length, int root, int dest) 123 | * 124 | * Send an array of variables 125 | */ 126 | 127 | inline void Multi::send(bool* array, int length, int root, int dest) 128 | { 129 | #ifdef MINT_MPI 130 | if (root == dest) 131 | return; 132 | if (_rank == root) 133 | MPI_Send(array, length, MPI_BYTE, dest, dest, MPI_COMM_WORLD); 134 | if (_rank == dest) 135 | MPI_Recv(array, length, MPI_BYTE, root, dest, MPI_COMM_WORLD, MPI_STATUS_IGNORE); 136 | #endif 137 | } 138 | 139 | inline void Multi::send(int* array, int length, int root, int dest) 140 | { 141 | #ifdef MINT_MPI 142 | if (root == dest) 143 | return; 144 | if (_rank == root) 145 | MPI_Send(array, length, MPI_INT, dest, dest, MPI_COMM_WORLD); 146 | if (_rank == dest) 147 | MPI_Recv(array, length, MPI_INT, root, dest, MPI_COMM_WORLD, MPI_STATUS_IGNORE); 148 | #endif 149 | } 150 | 151 | inline void Multi::send(unsigned long int* array, int length, int root, int dest) 152 | { 153 | #ifdef MINT_MPI 154 | if (root == dest) 155 | return; 156 | if (_rank == root) 157 | MPI_Send(array, length, MPI_UNSIGNED_LONG, dest, dest, MPI_COMM_WORLD); 158 | if (_rank == dest) 159 | MPI_Recv(array, length, MPI_UNSIGNED_LONG, root, dest, MPI_COMM_WORLD, MPI_STATUS_IGNORE); 160 | #endif 161 | } 162 | 163 | inline void Multi::send(double* array, int length, int root, int dest) 164 | { 165 | #ifdef MINT_MPI 166 | if (root == dest) 167 | return; 168 | if (_rank == root) 169 | MPI_Send(array, length, MPI_DOUBLE, dest, dest, MPI_COMM_WORLD); 170 | if (_rank == dest) 171 | MPI_Recv(array, length, MPI_DOUBLE, root, dest, MPI_COMM_WORLD, MPI_STATUS_IGNORE); 172 | #endif 173 | } 174 | 175 | inline void Multi::send(char* array, int length, int root, int dest) 176 | { 177 | #ifdef MINT_MPI 178 | if (root == dest) 179 | return; 180 | if (_rank == root) 181 | MPI_Send(array, length, MPI_CHAR, dest, dest, MPI_COMM_WORLD); 182 | if (_rank == dest) 183 | MPI_Recv(array, length, MPI_CHAR, root, dest, MPI_COMM_WORLD, MPI_STATUS_IGNORE); 184 | #endif 185 | } 186 | 187 | inline void Multi::send(Vector3D& vector, int root, int dest) 188 | { 189 | #ifdef MINT_MPI 190 | if (root == dest) 191 | return; 192 | if (_rank == root) 193 | MPI_Send(vector._vector, 3, MPI_DOUBLE, dest, dest, MPI_COMM_WORLD); 194 | if (_rank == dest) 195 | MPI_Recv(vector._vector, 3, MPI_DOUBLE, root, dest, MPI_COMM_WORLD, MPI_STATUS_IGNORE); 196 | #endif 197 | } 198 | 199 | 200 | 201 | /* inline void Multi::broadcast(TYPE* array, int length, int root) 202 | * 203 | * Broadcast an array of variables 204 | */ 205 | 206 | inline void Multi::broadcast(bool* array, int length, int root) 207 | { 208 | #ifdef MINT_MPI 209 | MPI_Bcast(array, length, MPI_BYTE, root, MPI_COMM_WORLD); 210 | #endif 211 | } 212 | 213 | inline void Multi::broadcast(int* array, int length, int root) 214 | { 215 | #ifdef MINT_MPI 216 | MPI_Bcast(array, length, MPI_INT, root, MPI_COMM_WORLD); 217 | #endif 218 | } 219 | 220 | inline void Multi::broadcast(unsigned long int* array, int length, int root) 221 | { 222 | #ifdef MINT_MPI 223 | MPI_Bcast(array, length, MPI_UNSIGNED_LONG, root, MPI_COMM_WORLD); 224 | #endif 225 | } 226 | 227 | inline void Multi::broadcast(double* array, int length, int root) 228 | { 229 | #ifdef MINT_MPI 230 | MPI_Bcast(array, length, MPI_DOUBLE, root, MPI_COMM_WORLD); 231 | #endif 232 | } 233 | 234 | inline void Multi::broadcast(char* array, int length, int root) 235 | { 236 | #ifdef MINT_MPI 237 | MPI_Bcast(array, length, MPI_CHAR, root, MPI_COMM_WORLD); 238 | #endif 239 | } 240 | 241 | inline void Multi::broadcast(Vector3D& vector, int root) 242 | { 243 | #ifdef MINT_MPI 244 | MPI_Bcast(vector._vector, 3, MPI_DOUBLE, root, MPI_COMM_WORLD); 245 | #endif 246 | } 247 | 248 | inline void Multi::broadcast(Vector& vector, int root) 249 | { 250 | #ifdef MINT_MPI 251 | int length = vector._length; 252 | MPI_Bcast(&length, 1, MPI_INT, root, MPI_COMM_WORLD); 253 | vector.length(length); 254 | MPI_Bcast(vector._vector, length, MPI_DOUBLE, root, MPI_COMM_WORLD); 255 | #endif 256 | } 257 | 258 | 259 | 260 | #endif 261 | -------------------------------------------------------------------------------- /src/output.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | #ifndef OUTPUT_H 23 | #define OUTPUT_H 24 | 25 | 26 | 27 | #include "num.h" 28 | #include "list.h" 29 | #include "text.h" 30 | #include 31 | #include 32 | using namespace std; 33 | 34 | 35 | 36 | // Define properties 37 | enum PrintType {ORDINARY, WARNING, ERROR}; 38 | enum PrintMethod {STANDARD, RESTRICTED}; 39 | enum PrintAlign {LEFT, RIGHT}; 40 | 41 | 42 | 43 | // Class to store information about a stream 44 | class StreamInfo 45 | { 46 | 47 | // Variables 48 | bool _streamIsSet; 49 | ostream* _stream; 50 | ofstream _outfile; 51 | Word _outfileName; 52 | int _numLinesBefore; 53 | int _numLinesAfter; 54 | int _havePrinted; 55 | bool _hold; 56 | PrintMethod _method; 57 | PrintType _type; 58 | bool _showTermination; 59 | bool _ordinaryOn; 60 | bool _warningsOn; 61 | bool _errorsOn; 62 | bool _print; 63 | int _maxLevel; 64 | int _spacesPerLevel; 65 | int _currentLevel; 66 | List _prevOrdinaryOn; 67 | List _prevWarningsOn; 68 | List _prevErrorsOn; 69 | 70 | // Functions 71 | void updatePrint(); 72 | 73 | public: 74 | 75 | // Constructor and destructor 76 | StreamInfo(); 77 | ~StreamInfo(); 78 | 79 | // Startup function 80 | void setup(ostream* input, int numBlankLinesAtStart = 0, int numBlankLinesAtEnd = 1); 81 | void setup(const Word& file, int numBlankLinesAtStart = 0, int numBlankLinesAtEnd = 1); 82 | 83 | // Functions 84 | void quietOn(bool warningsOff, bool errorsOff); 85 | void quietOff(); 86 | 87 | // Set functions 88 | void havePrinted(int input) { _havePrinted = input; } 89 | void hold(bool input) { _hold = input; } 90 | void method(PrintMethod input) { _method = input; updatePrint(); } 91 | void type(PrintType input) { _type = input; updatePrint(); } 92 | void showTermination(bool input) { _showTermination = input; } 93 | void ordinaryOn(bool input) { _ordinaryOn = input; updatePrint(); } 94 | void warningsOn(bool input) { _warningsOn = input; updatePrint(); } 95 | void errorsOn(bool input) { _errorsOn = input; updatePrint(); } 96 | void maxLevel(int input) { _maxLevel = input; } 97 | void spacesPerLevel(int input) { _spacesPerLevel = input; } 98 | void currentLevel(int input) { _currentLevel = input; updatePrint(); } 99 | 100 | // Access functions 101 | bool print() const { return _print; } 102 | bool hold() const { return _hold; } 103 | bool ordinaryOn() const { return _ordinaryOn; } 104 | bool warningsOn() const { return _warningsOn; } 105 | bool errorsOn() const { return _errorsOn; } 106 | bool showTermination() const { return _showTermination; } 107 | bool streamIsSet() const { return _streamIsSet; } 108 | int havePrinted() const { return _havePrinted; } 109 | int numLinesBefore() const { return _numLinesBefore; } 110 | int currentLevel() const { return _currentLevel; } 111 | int maxLevel() const { return _maxLevel; } 112 | int spacesPerLevel() const { return _spacesPerLevel; } 113 | PrintMethod method() const { return _method; } 114 | PrintType type() const { return _type; } 115 | ostream& stream() const { return *_stream; } 116 | }; 117 | 118 | 119 | 120 | // Class for output 121 | class Output 122 | { 123 | 124 | // Variables 125 | bool _addSpaces; 126 | Text _data; 127 | 128 | // Functions 129 | static double checkZero(double in, int prec); 130 | static int roundToOne(double in); 131 | 132 | // Static helper variables 133 | static char _arg[10]; 134 | static char _buffer[50]; 135 | 136 | // Static variables to control run time output 137 | static List _ids; 138 | static OList _streams; 139 | static int _primary; 140 | static int _curStream; 141 | 142 | public: 143 | 144 | // Constructor 145 | Output() { _addSpaces = true; } 146 | 147 | // Initialize 148 | static void initialize(); 149 | 150 | // Functions 151 | void clear() { _data.clear(); } 152 | void addSpaces(bool input) { _addSpaces = input; } 153 | void add(int input); 154 | void add(double input, int prec = 8); 155 | void addSci(double input, int prec = 8); 156 | void add(const char* input) { _data.addWord(input); } 157 | void add(const Word& input) { _data.addWord(input); } 158 | void add(const Words& input) { _data.addWords(input); } 159 | void addTab(); 160 | void addLine() { _data.addLine(); } 161 | void addLine(const char* line) { _data.addLine(line); } 162 | void addLines(int numToAdd) { _data.addLines(numToAdd); } 163 | void addWords(int numToAdd) { _data.addWords(numToAdd); } 164 | void addWords(int line, int numToAdd) { _data.addWords(line, numToAdd); } 165 | int numLines() const { return _data.length(); } 166 | 167 | // Add and remove streams 168 | static int addStream(ostream* input, int numBlankLinesAtStart = 0, int numBlankLinesAtEnd = 1); 169 | static int addStream(const Word& input, int numBlankLinesAtStart = 0, int numBlankLinesAtEnd = 1); 170 | static void removeStream(int inID); 171 | 172 | // Change between streams 173 | static void setPrimary() { _curStream = _primary; } 174 | static void setPrimary(int inID); 175 | static void setStream(int inID); 176 | 177 | // Direct access to streams 178 | static ostream& stream() { return _streams[_curStream].stream(); } 179 | 180 | // Access information about streams 181 | static bool ordinaryOn() { return _streams[_curStream].ordinaryOn(); } 182 | static bool warningsOn() { return _streams[_curStream].warningsOn(); } 183 | static bool errorsOn() { return _streams[_curStream].errorsOn(); } 184 | /** @return ID of currently-active output stream */ 185 | static int streamID() { return _ids[_curStream]; } 186 | static int primaryStreamID() { return _ids[_primary]; } 187 | static PrintMethod method() { return _streams[_curStream].method(); } 188 | static int level() { return _streams[_curStream].currentLevel(); } 189 | static List onOff(); 190 | 191 | // Set properties of streams 192 | static void maxLevel(int input) { _streams[_curStream].maxLevel(input); } 193 | static void spacesPerLevel(int input) { _streams[_curStream].spacesPerLevel(input); } 194 | static void ordinaryOn(bool input) { _streams[_curStream].ordinaryOn(input); } 195 | static void warningsOn(bool input) { _streams[_curStream].warningsOn(input); } 196 | static void errorsOn(bool input) { _streams[_curStream].errorsOn(input); } 197 | static void method(PrintMethod input); 198 | static void level(int input) { _streams[_curStream].currentLevel(input); } 199 | static void onOff(const List& input) { ordinaryOn(input[0]); warningsOn(input[1]); errorsOn(input[2]); } 200 | static void quietOn(bool warningsOff = false, bool errorsOff = false) 201 | { _streams[_curStream].quietOn(warningsOff, errorsOff); } 202 | static void quietOff() { _streams[_curStream].quietOff(); } 203 | 204 | // Static print functions 205 | static void increase() { _streams[_curStream].currentLevel(_streams[_curStream].currentLevel() + 1); } 206 | static void decrease() { _streams[_curStream].currentLevel(_streams[_curStream].currentLevel() - 1); } 207 | static void newline(PrintType input = ORDINARY); 208 | static void tab(); 209 | static void print(char message); 210 | static void print(const char* messsage); 211 | static void print(const Word& message) { print(message.array()); } 212 | static void print(int message); 213 | static void print(unsigned long int message); 214 | static void print(double message, int prec = -1); 215 | static void printSci(double message, int prec = -1); 216 | static void print(const Words& message, bool useComma = true, bool useAnd = true); 217 | static void print(const List& message, bool useComma = true, bool useAnd = true); 218 | static void print(const List& message, int prec, bool useComma = true, bool useAnd = true); 219 | static void print(const Vector3D& message, int prec, bool useComma = true); 220 | static void print(const Output& message, PrintAlign align, PrintType input = ORDINARY); 221 | static void print(const Output& message, const List& align, PrintType input = ORDINARY); 222 | 223 | // Static print functions with padding 224 | static void printPadded(int message, int width, PrintAlign align); 225 | static void printPadded(double message, int width, PrintAlign align, int prec = -1); 226 | static void printPaddedSci(double message, int width, PrintAlign align, int prec = -1); 227 | 228 | // Static exit functions 229 | static void turnOffExitFun() { _streams[_curStream].showTermination(false); } 230 | static void quit(); 231 | 232 | // Friends 233 | friend class StreamInfo; 234 | friend class OutputHelper; 235 | }; 236 | 237 | 238 | 239 | #endif 240 | -------------------------------------------------------------------------------- /src/pdf.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef PDF_H 24 | #define PDF_H 25 | 26 | 27 | 28 | #include "iso.h" 29 | #include "diffraction.h" 30 | #include "text.h" 31 | #include "fileSystem.h" 32 | 33 | 34 | 35 | // Class to interpret powder diffraction file 36 | class PDF 37 | { 38 | public: 39 | 40 | // Read file 41 | static void read(ExperimentalPattern& diffraction, Text content, ISO* iso = 0); 42 | static void read(ExperimentalPattern& diffraction, const Word& file, ISO* iso = 0) 43 | { read(diffraction, Read::text(file), iso); } 44 | 45 | // Check if file is in correct format 46 | static bool isFormat(const Text& content); 47 | static bool isFormat(const Word& file) { return isFormat(Read::text(file)); } 48 | }; 49 | 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/phonons.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef PHONONS_H 24 | #define PHONONS_H 25 | 26 | 27 | 28 | #include "iso.h" 29 | #include "symmetry.h" 30 | #include "potential.h" 31 | #include "text.h" 32 | #include "fileSystem.h" 33 | #include "num.h" 34 | #include "list.h" 35 | 36 | 37 | 38 | // Class for calculating phonons 39 | class Phonons 40 | { 41 | 42 | // Variables 43 | bool _isSet; 44 | bool _writeFCFile; 45 | Matrix _forceConstants; 46 | Matrix _massFactors; 47 | OList::D2 _vectors; 48 | 49 | // Functions 50 | static void getForceConstants(Vector& constants, const ISO& iso, const Symmetry& symmetry, \ 51 | const Potential& potential, Atom* atom, int direction); 52 | static void sortModes(CVector& freqs, CMatrix& modes, int left, int right); 53 | static void moveAcousticToStart(CVector& freqs, CMatrix& modes); 54 | static bool isAcoustic(CMatrix& modes, int index); 55 | static void sortModes(CVector& freqs, List& indices, int left, int right); 56 | 57 | public: 58 | 59 | // Constructor 60 | Phonons() { _isSet = false; _writeFCFile = true; } 61 | 62 | // Assignment 63 | Phonons& operator= (const Phonons& rhs); 64 | 65 | // Setup functions 66 | void clear(); 67 | Word generateForceConstants(const ISO& iso, const Potential& potential, const Word& fileAppend); 68 | Word generateForceConstants(const ISO& iso, const Symmetry& symmetry, const Potential& potential, \ 69 | const Word& fileAppend); 70 | void set(const Text& content); 71 | 72 | // Set settings 73 | void writeForceConstantsFile(bool input) { _writeFCFile = input; } 74 | 75 | // Get modes at given reciprocal lattice vector 76 | CVector frequencies(const Vector3D& qFrac, CMatrix* modes = 0) const; 77 | 78 | // Access functions 79 | bool isSet() const { return _isSet; } 80 | const Matrix& forceConstants() const { return _forceConstants; } 81 | 82 | // Other functions 83 | static bool isForceConstantFile(const Text& content); 84 | static bool isForceConstantFile(const Word& file) { return isForceConstantFile(Read::text(file)); } 85 | }; 86 | 87 | 88 | 89 | /* inline void Phonons::clear() 90 | * 91 | * Clear data in phonons object 92 | */ 93 | 94 | inline void Phonons::clear() 95 | { 96 | _isSet = false; 97 | _forceConstants.clear(); 98 | _massFactors.clear(); 99 | _vectors.clear(); 100 | } 101 | 102 | 103 | 104 | /* inline Phonons& Phonons::operator= (const Phonons& rhs) 105 | * 106 | * Assignment operator for phonons 107 | */ 108 | 109 | inline Phonons& Phonons::operator= (const Phonons& rhs) 110 | { 111 | if (this != &rhs) 112 | { 113 | clear(); 114 | _isSet = rhs._isSet; 115 | _forceConstants = rhs._forceConstants; 116 | _massFactors = rhs._massFactors; 117 | _vectors = rhs._vectors; 118 | } 119 | return *this; 120 | } 121 | 122 | 123 | 124 | /* inline Word Phonons::generateForceConstants(const ISO& iso, const Potential& potential, const Word& fileAppend) 125 | * 126 | * Evaluate force constants without symmetry 127 | */ 128 | 129 | inline Word Phonons::generateForceConstants(const ISO& iso, const Potential& potential, const Word& fileAppend) 130 | { 131 | Symmetry symmetry; 132 | symmetry.setToP1(iso); 133 | return generateForceConstants(iso, symmetry, potential, fileAppend); 134 | } 135 | 136 | 137 | 138 | #endif 139 | -------------------------------------------------------------------------------- /src/pointGroup.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef POINTGROUP_H 24 | #define POINTGROUP_H 25 | 26 | 27 | 28 | #include "num.h" 29 | #include "iso.h" 30 | #include "symmetry.h" 31 | #include "text.h" 32 | #include "list.h" 33 | 34 | 35 | 36 | // Class to store point group information 37 | class PointGroup 38 | { 39 | 40 | // variables 41 | bool _centric; 42 | int _number; 43 | int _order; 44 | int _laueGroup; 45 | CenteringType _centeringType; 46 | CrystalSystem _crystalSystem; 47 | Word _schoenflies; 48 | Word _hermannMauguinShort; 49 | Word _hermannMauguin; 50 | Matrix3D _redToConv; 51 | Matrix3D _unitToConv; 52 | OList _convSymmetry; 53 | 54 | // General functions 55 | void setByNumber(int number); 56 | void setProperties(int number, bool centric, int order, const char* schoe, const char* hmShort, const char* hm, \ 57 | int laueGroup, CrystalSystem crystalSystem); 58 | 59 | // Helper functions to get point group from name 60 | static int getNumberFromName(const Word& name); 61 | static bool compareName(const Word& name, const char* schoe, const char* hmShort, const char* hmFull); 62 | 63 | // Helper functions to get point group of structure 64 | int getNumberFromOperations(const Symmetry& symmetry); 65 | void setRedToConv(const ISO& reducedCell, const Symmetry& symmetry); 66 | static double getAngle(const Vector3D& vec1, const Vector3D& vec2, const Basis& basis); 67 | void setConvSymmetry(const Symmetry& symmetry); 68 | 69 | public: 70 | 71 | // Constructor 72 | PointGroup() {} 73 | PointGroup(const PointGroup& copy) { *this = copy; } 74 | 75 | // Setup functions 76 | void clear(); 77 | PointGroup& operator= (const PointGroup& rhs); 78 | 79 | // Set point group by name or symmetry operations 80 | bool set(const Word& name, bool quitIfNotFound = true); 81 | void set(const ISO& iso, double tol); 82 | 83 | // Print functions 84 | void print() const; 85 | static void printAll(); 86 | 87 | // Static member functions 88 | static bool isPointGroup(const Word& name) { return (getNumberFromName(name) != 0); } 89 | static bool findTranslation(const OList& centVecs, double val1, double val2, double val3); 90 | 91 | // Access functions 92 | bool centric() const { return _centric; } 93 | int number() const { return _number; } 94 | int order() const { return _order; } 95 | int laueGroup() const { return _laueGroup; } 96 | CenteringType centeringType() const { return _centeringType; } 97 | CrystalSystem crystalSystem() const { return _crystalSystem; } 98 | const Word& schoenflies() const { return _schoenflies; } 99 | const Word& hermannMauguinShort() const { return _hermannMauguinShort; } 100 | const Word& hermannMauguin() const { return _hermannMauguin; } 101 | const Matrix3D& redToConv() const { return _redToConv; } 102 | const Matrix3D& unitToConv() const { return _unitToConv; } 103 | const OList& convSymmetry() const { return _convSymmetry; } 104 | }; 105 | 106 | 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /src/random.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #include "num.h" 24 | #include "multi.h" 25 | #include "random.h" 26 | #include "output.h" 27 | #include "constants.h" 28 | #include 29 | 30 | 31 | 32 | /* void Random::set(RandomPackage package, unsigned long int seed) 33 | * 34 | * Set the random number generator 35 | */ 36 | 37 | void Random::set(RandomPackage package, unsigned long int seed) 38 | { 39 | 40 | // Set package 41 | if (package == RP_MERSENNE) 42 | { 43 | 44 | // Set method 45 | delete _generator; 46 | _generator = new Mersenne; 47 | _generator->seed(seed); 48 | return; 49 | } 50 | 51 | // Unknown package 52 | Output::newline(ERROR); 53 | Output::print("Attempting to set random number generator with unknown package"); 54 | Output::quit(); 55 | } 56 | 57 | 58 | 59 | /* int Random::integerOnNormal(int min, int max, double mean, double standardDeviation) const 60 | * 61 | * Generate a random integer on normal distribution 62 | */ 63 | 64 | int Random::integerOnNormal(int min, int max, double mean, double standardDeviation) const 65 | { 66 | 67 | // Figure out range 68 | double range = max - mean + 0.5; 69 | if (mean - min > range) 70 | range = mean - min + 0.5; 71 | 72 | // Loop until a random number is found that is good 73 | double res; 74 | do 75 | { 76 | res = Num::round(decimalOnNormal(mean, standardDeviation, range), 1); 77 | } 78 | while ((res < min) || (res > max)); 79 | 80 | // Return result 81 | return (int)Num::round(res, 1); 82 | } 83 | 84 | 85 | 86 | /* double Random::decimalOnNormal(double mean, double standardDeviation, double range) const 87 | * 88 | * Generate a random double on normal distribution 89 | */ 90 | 91 | double Random::decimalOnNormal(double mean, double standardDeviation, double range) const 92 | { 93 | 94 | // Is spare is set then use it 95 | double res; 96 | if (_normalSpareSet == true) 97 | { 98 | _normalSpareSet = false; 99 | res = mean + _normalSpare * standardDeviation; 100 | if ((res >= mean - range) && (res <= mean + range)) 101 | return res; 102 | } 103 | 104 | // Loop until value is in range 105 | double mag; 106 | double mult; 107 | double rand[2]; 108 | do 109 | { 110 | 111 | // Get random numbers 112 | do 113 | { 114 | rand[0] = decimal(0, 1) * 2 - 1; 115 | rand[1] = decimal(0, 1) * 2 - 1; 116 | mag = rand[0]*rand[0] + rand[1]*rand[1]; 117 | } while ((mag >= 1) || (mag == 0)); 118 | 119 | // Save multiplier 120 | mult = sqrt(-2 * log(mag) / mag); 121 | 122 | // Save spare value 123 | _normalSpareSet = true; 124 | _normalSpare = mult * rand[1]; 125 | 126 | // Save result 127 | res = mean + standardDeviation * rand[0] * mult; 128 | } while ((res < mean - range) || (res > mean + range)); 129 | 130 | // Return result 131 | return res; 132 | } 133 | 134 | 135 | 136 | /* unsigned long int Random::readTSC(bool uniqueOnEachProcessor) 137 | * 138 | * Return the value of the time stamp counter 139 | */ 140 | 141 | unsigned long int Random::readTSC(bool uniqueOnEachProcessor) 142 | { 143 | 144 | // Setup 145 | unsigned int lo; 146 | unsigned int hi; 147 | __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); 148 | 149 | // Send value 150 | unsigned long int res = ((unsigned long int) hi << 32) | lo; 151 | 152 | // Broadcast value if needed 153 | if (!uniqueOnEachProcessor) 154 | { 155 | unsigned long int sent = res; 156 | Multi::broadcast(sent, 0); 157 | res = sent; 158 | } 159 | 160 | // Return result 161 | return res; 162 | } 163 | 164 | -------------------------------------------------------------------------------- /src/random.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef RANDOM_H 24 | #define RANDOM_H 25 | 26 | 27 | 28 | #include "mtwist.h" 29 | #include "randistrs.h" 30 | 31 | 32 | 33 | // Random number generator packages 34 | enum RandomPackage {RP_UNKNOWN, RP_MERSENNE}; 35 | 36 | 37 | 38 | // Class to deal with random number generators 39 | class Random 40 | { 41 | 42 | // Base class for random number generators 43 | class Generator 44 | { 45 | public: 46 | virtual ~Generator() {} 47 | virtual void seed(unsigned long int seed) = 0; 48 | virtual int integer(int min, int max) const = 0; 49 | virtual double decimal(double min, double max) const = 0; 50 | }; 51 | 52 | // Mersenne generator 53 | class Mersenne : public Generator 54 | { 55 | mutable mt_distribution _generator; 56 | public: 57 | void seed(unsigned long int seed) { _generator.seed32(seed); } 58 | int integer(int min, int max) const { return _generator.iuniform(min, max+1); } 59 | double decimal(double min, double max) const { return _generator.uniform(min, max); } 60 | }; 61 | 62 | // Variable to store generator 63 | Generator* _generator; 64 | mutable bool _normalSpareSet; 65 | mutable double _normalSpare; 66 | 67 | public: 68 | 69 | // Constructor and destructor 70 | Random() { _generator = new Mersenne; _generator->seed(readTSC()); _normalSpareSet = false; } 71 | ~Random() { delete _generator; } 72 | 73 | // Setup functions 74 | void set(RandomPackage package, unsigned long int seed); 75 | void set(RandomPackage package) { set(package, readTSC()); } 76 | void seed(unsigned long int seed) { _generator->seed(seed); } 77 | 78 | // Uniform distributions 79 | int integer(int min, int max) const { return _generator->integer(min, max); } 80 | double decimal(double min, double max) const { return _generator->decimal(min, max); } 81 | 82 | // Non-uniform distributions 83 | int integerOnNormal(int min, int max, double mean, double standardDeviation) const; 84 | double decimalOnNormal(double mean, double standardDeviation, double range) const; 85 | 86 | // Static member functions 87 | static unsigned long int readTSC(bool uniqueOnEachProcessor = false); 88 | }; 89 | 90 | 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /src/randomStructure.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef RANDOMSTRUCTURE_H 24 | #define RANDOMSTRUCTURE_H 25 | 26 | 27 | 28 | #include "num.h" 29 | #include "iso.h" 30 | #include "spaceGroup.h" 31 | #include "symmetry.h" 32 | #include "random.h" 33 | #include "list.h" 34 | 35 | 36 | 37 | // Class to generate a random structure 38 | class RandomStructure 39 | { 40 | 41 | // Static member variables 42 | static int _maxTrialLoops; 43 | static double _minBondFraction; 44 | static double _weights[143]; 45 | 46 | // General helper functions 47 | static Matrix3D generateBasis(const Matrix3D origMat, double min, double max, Random& random, \ 48 | const Symmetry* symmetry = 0); 49 | static Matrix3D generateBasis(double targetVolume, Random& random, \ 50 | LatticeSystem latticeSystem = LS_TRICLINIC); 51 | static List::D2 getAtomsToAssign(ISO& iso); 52 | static int weightBin(double ratio) { return (int)((ratio + 1e-6 - 0.95)/0.05); } 53 | static double weight(int index) { return ((index >= 143) || (index < 0)) ? 0 : _weights[index]; } 54 | static double weight(double ratio) { return weight(weightBin(ratio)); } 55 | 56 | // Generate structure without symmetry 57 | static void generateWithoutSymmetry(ISO& iso, double targetVolume, Random& random, Symmetry* symmetry); 58 | static void generatePositions(ISO& iso, Random& random); 59 | 60 | // Generate structure with symmetry 61 | static bool generateWithSymmetry(ISO& iso, double targetVolume, Random& random, double bias, Symmetry* symmetry); 62 | static void generatePositions(ISO& iso, Random& random, const SpaceGroup& spaceGroup, double bias, \ 63 | Symmetry* symmetry); 64 | static List::D2 getWyckoffGroups(const ISO& iso, const SpaceGroup& spaceGroup, double minRadius); 65 | static void sortWyckoffGroups(List::D2& groups, int left, int right); 66 | static void getAllowedWyckoff(Linked::D2>& allowedGroups, const List::D2& atomsToAssign, \ 67 | const List::D2 wyckoffGroups); 68 | static void recurseAllowedWyckoff(Linked::D2>& res, const List::D2& atomsToAssign, \ 69 | const List::D2 wyckoffGroups, const List& limited, const List& numUsed, \ 70 | const List::D2& curList, int curAtom, int curGroup); 71 | 72 | public: 73 | 74 | // Setup functions 75 | static void maxTrialLoops(int input) { _maxTrialLoops = input; } 76 | static void minBondFraction(double input) { _minBondFraction = input; } 77 | 78 | // Perturb functions 79 | static void perturbBasis(ISO& iso, double min, double max, Random& random); 80 | static void perturbAtoms(ISO& iso, double min, double max, Random& random); 81 | 82 | // Perturb using symmetry 83 | static void perturbBasis(ISO& iso, const Symmetry& symmetry, double min, double max, Random& random); 84 | static void perturbAtoms(ISO& iso, const Symmetry& symmetry, double min, double max, Random& random); 85 | 86 | // Generate structure 87 | static bool generate(ISO& iso, Random& random) 88 | { return generate(iso, random, 1, 0); } 89 | static bool generate(ISO& iso, Random& random, double bias) 90 | { return generate(iso, random, bias, 0); } 91 | static bool generate(ISO& iso, Random& random, Symmetry* symmetry) 92 | { return generate(iso, random, 1, symmetry); } 93 | static bool generate(ISO& iso, Random& random, double bias, Symmetry* symmetry); 94 | 95 | // Useful operations 96 | static bool setSiteSymmetry(const ISO& iso, const SpaceGroup& spaceGroup, Symmetry* symmetry); 97 | }; 98 | 99 | 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /src/relax.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #include "relax.h" 24 | #include "output.h" 25 | #include 26 | 27 | 28 | 29 | /* void Relax::structure(ISO& iso, const LocalPotential& potential, const Symmetry* symmetry) const 30 | * 31 | * Run relaxation 32 | */ 33 | 34 | void Relax::structure(ISO& iso, const LocalPotential& potential, const Symmetry* symmetry) const 35 | { 36 | 37 | // Steepest descent run 38 | if (_relaxMethod == RM_STEEPEST_DESCENT) 39 | _getLineDirection = &Relax::SD; 40 | 41 | // Conjugate gradient run 42 | else if (_relaxMethod == RM_CONJUGATE_GRADIENT) 43 | _getLineDirection = &Relax::CG; 44 | 45 | // Unknown method 46 | else 47 | { 48 | Output::newline(ERROR); 49 | Output::print("Unknown relaxation method"); 50 | Output::quit(); 51 | } 52 | 53 | // Output 54 | Output::newline(); 55 | Output::print("Relaxing internal coordinates using "); 56 | Output::print(relaxMethod(_relaxMethod).tolower()); 57 | Output::print(" algorithm"); 58 | Output::increase(); 59 | 60 | // Loop until max loops is reached or converged 61 | int i, j, k; 62 | int loopNum; 63 | double stepScale; 64 | Vector3D newPos; 65 | OList direction; 66 | for (loopNum = 0; loopNum < _maxIterations; ++loopNum) 67 | { 68 | 69 | // Output 70 | Output::newline(); 71 | if (loopNum == 0) 72 | Output::print("Initial structure"); 73 | else 74 | { 75 | Output::print("Step "); 76 | Output::print(loopNum); 77 | } 78 | Output::increase(); 79 | 80 | // Evaluate the forces 81 | _prevForces = _forces; 82 | evaluateForces(_forces, iso, potential, symmetry, true); 83 | 84 | // Output 85 | Output::decrease(); 86 | 87 | // Break if converged 88 | if (areForcesConverged()) 89 | break; 90 | 91 | // Break if at max iterations 92 | if (loopNum == _maxIterations - 1) 93 | break; 94 | 95 | // Get the line search direction 96 | (this->*_getLineDirection)(direction); 97 | 98 | // Get the step size to make 99 | stepScale = lineSearch(direction, iso, potential, symmetry); 100 | 101 | // Set the new positions 102 | for (i = 0; i < iso.atoms().length(); ++i) 103 | { 104 | for (j = 0; j < iso.atoms()[i].length(); ++j) 105 | { 106 | newPos = _origPositions[i][j]; 107 | for (k = 0; k < 3; ++k) 108 | newPos[k] += stepScale * direction[iso.atoms()[i][j].atomNumber()][k]; 109 | iso.atoms()[i][j].cartesian(newPos); 110 | } 111 | } 112 | } 113 | 114 | // Did not converged 115 | if (loopNum >= _maxIterations - 1) 116 | { 117 | Output::newline(WARNING); 118 | Output::print("Failed to reach convergence criterion"); 119 | } 120 | 121 | // Output 122 | Output::decrease(); 123 | } 124 | 125 | 126 | 127 | /* void Relax::SD(OList& direction) const 128 | * 129 | * Steepest descent minimization 130 | */ 131 | 132 | void Relax::SD(OList& direction) const 133 | { 134 | direction = _forces; 135 | } 136 | 137 | 138 | 139 | /* void Relax::CG(OList& direction) const 140 | * 141 | * Conjugate gradient minimization 142 | */ 143 | 144 | void Relax::CG(OList& direction) const 145 | { 146 | 147 | // Get the magnitude of the previous forces 148 | int i; 149 | double prevForceMag = 0; 150 | for (i = 0; i < _prevForces.length(); ++i) 151 | prevForceMag += _prevForces[i] * _prevForces[i]; 152 | 153 | // Set the scaling factor 154 | double scale = 0; 155 | if (prevForceMag != 0) 156 | { 157 | double forceMag = 0; 158 | for (i = 0; i < _forces.length(); ++i) 159 | forceMag += _forces[i] * _forces[i]; 160 | scale = forceMag / prevForceMag; 161 | } 162 | 163 | // Set the direction 164 | if ((scale == 0) || (scale > 1)) 165 | direction = _forces; 166 | else 167 | { 168 | int j; 169 | for (i = 0; i < _forces.length(); ++i) 170 | { 171 | for (j = 0; j < 3; ++j) 172 | direction[i][j] = _forces[i][j] + scale * direction[i][j]; 173 | } 174 | } 175 | } 176 | 177 | 178 | 179 | /* double Relax::lineSearch(OList& direction, ISO& iso, const LocalPotential& potential, 180 | * Symmetry* symmetry) const 181 | * 182 | * Search for minimum along set direction 183 | */ 184 | 185 | double Relax::lineSearch(OList& direction, ISO& iso, const LocalPotential& potential, \ 186 | const Symmetry* symmetry) const 187 | { 188 | 189 | // Save the current positions 190 | int i, j; 191 | _origPositions.length(iso.atoms().length()); 192 | for (i = 0; i < iso.atoms().length(); ++i) 193 | { 194 | _origPositions[i].length(iso.atoms()[i].length()); 195 | for (j = 0; j < iso.atoms()[i].length(); ++j) 196 | _origPositions[i][j] = iso.atoms()[i][j].cartesian(); 197 | } 198 | 199 | // Get the max step size 200 | double curStep; 201 | double curMaxStep = 0; 202 | for (i = 0; i < direction.length(); ++i) 203 | { 204 | curStep = direction[i]*direction[i]; 205 | if (curStep > curMaxStep) 206 | curMaxStep = curStep; 207 | } 208 | 209 | // Set the scaling 210 | curMaxStep = sqrt(curMaxStep); 211 | double scale = (_lineSearchScale*curMaxStep > _maxStep) ? _maxStep / curMaxStep : _lineSearchScale; 212 | 213 | // Set the next positions 214 | int k; 215 | Vector3D newPos; 216 | for (i = 0; i < iso.atoms().length(); ++i) 217 | { 218 | for (j = 0; j < iso.atoms()[i].length(); ++j) 219 | { 220 | for (k = 0; k < 3; ++k) 221 | newPos[k] = _origPositions[i][j][k] + scale*direction[iso.atoms()[i][j].atomNumber()][k]; 222 | iso.atoms()[i][j].cartesian(newPos); 223 | } 224 | } 225 | 226 | // Evaluate the current forces 227 | evaluateForces(_forcesNext, iso, potential, symmetry, false); 228 | 229 | // Normalize direction vector 230 | double normalizer = 0; 231 | _dirNorm = direction; 232 | for (i = 0; i < _dirNorm.length(); ++i) 233 | normalizer += _dirNorm[i] * _dirNorm[i]; 234 | normalizer = sqrt(normalizer); 235 | for (i = 0; i < _dirNorm.length(); ++i) 236 | { 237 | for (j = 0; j < 3; ++j) 238 | _dirNorm[i][j] /= normalizer; 239 | } 240 | 241 | // Project original and next forces onto direction vector 242 | double forceProjOrig = 0; 243 | double forceProjNext = 0; 244 | for (i = 0; i < _dirNorm.length(); ++i) 245 | { 246 | forceProjOrig += _forces[i] * _dirNorm[i]; 247 | forceProjNext += _forcesNext[i] * _dirNorm[i]; 248 | } 249 | 250 | // Get the optimal position along the line (0 = orig, 1 = next) 251 | double opt = forceProjOrig / (forceProjOrig - forceProjNext); 252 | 253 | // Make sure result is in the range of -1 to 1 254 | if (Num::abs(opt) > 1) 255 | opt *= 1 / Num::abs(opt); 256 | 257 | // Return the scaling factor 258 | return opt * scale; 259 | } 260 | 261 | 262 | 263 | /* void Relax::evaluateForces(OList& forces, ISO& iso, const LocalPotential& potential, 264 | * const Symmetry* symmetry, bool print) const 265 | * 266 | * Evaluate the forces of the current structure 267 | */ 268 | 269 | void Relax::evaluateForces(OList& forces, ISO& iso, const LocalPotential& potential, \ 270 | const Symmetry* symmetry, bool print) const 271 | { 272 | 273 | // Not using symmetry 274 | if (!symmetry) 275 | potential.single(iso, 0, &forces); 276 | 277 | // Using symmetry 278 | else 279 | potential.single(iso, *symmetry, 0, &forces); 280 | 281 | // Save cartesian forces 282 | int i; 283 | for (i = 0; i < forces.length(); ++i) 284 | iso.basis().toCartesian(forces[i]); 285 | 286 | // Print forces 287 | if (print) 288 | { 289 | int j; 290 | for (i = 0; i < forces.length(); ++i) 291 | { 292 | Output::newline(); 293 | Output::print("Atom "); 294 | Output::print(i+1); 295 | Output::print(": "); 296 | for (j = 0; j < 3; ++j) 297 | { 298 | Output::printSci(forces[i][j], 8); 299 | Output::print(" "); 300 | } 301 | } 302 | } 303 | } 304 | 305 | 306 | 307 | /* bool Relax::areForcesConverged() const 308 | * 309 | * Check if all forces are below convergence tolerance 310 | */ 311 | 312 | bool Relax::areForcesConverged() const 313 | { 314 | int i, j; 315 | for (i = 0; i < _forces.length(); ++i) 316 | { 317 | for (j = 0; j < 3; ++j) 318 | { 319 | if ((_forces[i][j] < -_forceTol) || (_forces[i][j] > _forceTol)) 320 | return false; 321 | } 322 | } 323 | Output::newline(); 324 | Output::print("Reached convergence criterion"); 325 | return true; 326 | } 327 | -------------------------------------------------------------------------------- /src/relax.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef RELAX_H 24 | #define RELAX_H 25 | 26 | 27 | 28 | #include "iso.h" 29 | #include "symmetry.h" 30 | #include "locPotential.h" 31 | #include "text.h" 32 | #include "num.h" 33 | #include "list.h" 34 | 35 | 36 | 37 | // Relaxation methods 38 | enum RelaxMethod {RM_UNKNOWN, RM_STEEPEST_DESCENT, RM_CONJUGATE_GRADIENT}; 39 | 40 | 41 | 42 | // Class to perform structure relaxation 43 | class Relax 44 | { 45 | 46 | // Variable to store relaxation method 47 | mutable void (Relax::*_getLineDirection)(OList&) const; 48 | 49 | // Settings 50 | int _maxIterations; 51 | double _forceTol; 52 | double _lineSearchScale; 53 | double _maxStep; 54 | RelaxMethod _relaxMethod; 55 | 56 | // Storage variables 57 | mutable OList _forces; 58 | mutable OList _prevForces; 59 | mutable OList _forcesNext; 60 | mutable OList::D2 _origPositions; 61 | mutable OList _dirNorm; 62 | 63 | // Functions 64 | void structure(ISO& iso, const LocalPotential& potential, const Symmetry* symmetry) const; 65 | 66 | // Minimization methods 67 | void SD(OList& direction) const; 68 | void CG(OList& direction) const; 69 | 70 | // Helper functions 71 | double lineSearch(OList& direction, ISO& iso, const LocalPotential& potential, \ 72 | const Symmetry* symmetry) const; 73 | void evaluateForces(OList& forces, ISO& iso, const LocalPotential& potential, \ 74 | const Symmetry* symmetry, bool print) const; 75 | bool areForcesConverged() const; 76 | 77 | public: 78 | 79 | // Constructor 80 | Relax(); 81 | 82 | // Setup functions 83 | void maxIterations(int input) { _maxIterations = input; } 84 | void forceTolerance(double input) { _forceTol = input; } 85 | void lineSearchScale(double input) { _lineSearchScale = input; } 86 | void maxStep(double input) { _maxStep = input; } 87 | 88 | // Functions 89 | void structure(ISO& iso, const LocalPotential& potential) const 90 | { structure(iso, potential, 0); } 91 | void structure(ISO& iso, const LocalPotential& potential, const Symmetry& symmetry) const 92 | { structure(iso, potential, &symmetry); } 93 | 94 | // Helper functions 95 | static RelaxMethod relaxMethod(const Word& method); 96 | static Word relaxMethod(RelaxMethod method); 97 | }; 98 | 99 | 100 | 101 | /* inline Relax::Relax() 102 | * 103 | * Constructor for Relax object 104 | */ 105 | 106 | inline Relax::Relax() 107 | { 108 | _maxIterations = 100; 109 | _forceTol = 1e-9; 110 | _lineSearchScale = 1; 111 | _maxStep = 0.01; 112 | _relaxMethod = RM_CONJUGATE_GRADIENT; 113 | } 114 | 115 | 116 | 117 | /* inline RelaxMethod Relax::relaxMethod(const Word& method) 118 | * 119 | * Convert word to relaxation method 120 | */ 121 | 122 | inline RelaxMethod Relax::relaxMethod(const Word& method) 123 | { 124 | if (method.equal("steepest", false, 5)) 125 | return RM_STEEPEST_DESCENT; 126 | if (method.equal("conjugate", false, 4)) 127 | return RM_CONJUGATE_GRADIENT; 128 | return RM_UNKNOWN; 129 | } 130 | 131 | 132 | 133 | /* inline Word Relax::relaxMethod(RelaxMethod method) 134 | * 135 | * Convert relaxation method to word 136 | */ 137 | 138 | inline Word Relax::relaxMethod(RelaxMethod method) 139 | { 140 | switch (method) 141 | { 142 | case RM_STEEPEST_DESCENT: 143 | return Word("Steepest descent"); 144 | case RM_CONJUGATE_GRADIENT: 145 | return Word("Conjugate gradient"); 146 | default: 147 | return Word("Unknown"); 148 | } 149 | } 150 | 151 | 152 | 153 | #endif 154 | -------------------------------------------------------------------------------- /src/spaceGroup.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef SPACEGROUP_H 24 | #define SPACEGROUP_H 25 | 26 | 27 | 28 | #include "num.h" 29 | #include "iso.h" 30 | #include "symmetry.h" 31 | #include "pointGroup.h" 32 | #include "text.h" 33 | #include "list.h" 34 | 35 | 36 | 37 | // Class for a Wyckoff position and its orbit 38 | class Wyckoff 39 | { 40 | 41 | // Position variables 42 | int _rank; 43 | OList _rotations; 44 | OList _translations; 45 | 46 | // Identification variables 47 | char _letter[2]; 48 | Word _name; 49 | 50 | // Static member variables 51 | static char _letters[35][2]; 52 | 53 | public: 54 | 55 | // Constructor 56 | Wyckoff() { _letter[0] = '\0'; }; 57 | Wyckoff(const Wyckoff& copy) { *this = copy; } 58 | 59 | // General functions 60 | void clear(); 61 | Wyckoff& operator= (const Wyckoff& rhs); 62 | 63 | // Setup functions 64 | void set(int rotIndex, int transIndex, const OList& symmetry, int letterIndex); 65 | 66 | // Print functions 67 | void print() const; 68 | 69 | // Access functions 70 | int rank() const { return _rank; } 71 | int multiplicity() const { return _rotations.length(); } 72 | const char* letter() const { return _letter; } 73 | const Word& name() const { return _name; } 74 | const OList& rotations() const { return _rotations; } 75 | const OList& translations() const { return _translations; } 76 | Words getString(int index) const 77 | { return JonesFaithful::toString(_rotations[index], &_translations[index]); } 78 | }; 79 | 80 | 81 | 82 | // Class for a single space group 83 | class SpaceGroup 84 | { 85 | 86 | // Identification variables 87 | Word _itcNumber; 88 | Word _schoenflies; 89 | Word _hermannMauguinShort; 90 | Word _hermannMauguin; 91 | Word _hall; 92 | 93 | // Symmetry variables 94 | LatticeSystem _system; 95 | LatticeCentering _centering; 96 | OList _symmetry; 97 | Matrix3D _unitToConv; 98 | Vector3D _originShift; 99 | 100 | // Wyckoff data variables 101 | OList _wyckoff; 102 | 103 | // Point group variables 104 | PointGroup _pointGroup; 105 | 106 | // General functions 107 | void setByNumber(int number); 108 | void setName(const char* number, const char* schoe, const char* hmShort, const char* hmLong, const char* hall); 109 | void setSymmetry(int gen1, int vec1, int gen2, int vec2, int gen3, int vec3, int gen4, int vec4, \ 110 | LatticeSystem system, LatticeCentering centering); 111 | void addSymmetry(const Matrix3D& rotation, const Vector3D& translation); 112 | void setWyckoff(int wr1, int wt1, int wr2, int wt2, int wr3, int wt3, int wr4, int wt4, int wr5, int wt5, \ 113 | int wr6, int wt6, int wr7, int wt7, int wr8, int wt8, int wr9, int wt9, int wr10, int wt10, int wr11, \ 114 | int wt11, int wr12, int wt12, int wr13, int wt13, int wr14, int wt14, int wr15, int wt15, int wr16, \ 115 | int wt16, int wr17, int wt17, int wr18, int wt18, int wr19, int wt19, int wr20, int wt20, int wr21, \ 116 | int wt21, int wr22, int wt22, int wr23, int wt23, int wr24, int wt24, int wr25, int wt25, int wr26, \ 117 | int wt26, int wr27, int wt27); 118 | 119 | // Helper functions to get space group from name 120 | static int getNumberFromName(const Word& name, bool useNumber); 121 | static bool compareName(const Word& name, const char* number, const char* schoe, const char* hmShort, \ 122 | const char* hmFull, const char* hall, bool useNumber); 123 | 124 | // Helper functions to get space group from structure 125 | int getGeneratorIndex(const Matrix3D& rotation); 126 | int generatorsToNumber(int numOps, const List& gens, const OList& trans, \ 127 | const Matrix3D& conv); 128 | bool compGen(int numOps, const Matrix3D& conv, const List& gens, \ 129 | const OList& translations, int numSGOps, int gr1, int gt1, int gr2, int gt2, int gr3, \ 130 | int gt3, int gr4, int gt4, LatticeSystem system, LatticeCentering centering); 131 | Matrix3D generatorToMatrix(int index); 132 | Vector3D generatorToTranslation(int index); 133 | 134 | public: 135 | 136 | // Constructor 137 | SpaceGroup() {} 138 | SpaceGroup(const SpaceGroup& copy) { *this = copy; } 139 | SpaceGroup(const Word& name, bool useNumber = true, bool quitIfNotFound = true) 140 | { set(name, useNumber, quitIfNotFound); } 141 | SpaceGroup(const ISO& iso, double tol) { set(iso, tol); } 142 | 143 | // General functions 144 | void clear(); 145 | SpaceGroup& operator= (const SpaceGroup& rhs); 146 | 147 | // Setup functions 148 | bool set(const Word& name, bool useNumber = true, bool quitIfNotFound = true); 149 | void set(const ISO& iso, double tol); 150 | 151 | // Static member functions 152 | static bool isSpaceGroup(const Word& name, bool useNumber) { return (getNumberFromName(name, useNumber) != -1); } 153 | static Matrix3D conventionalTransformation(const ISO& iso, double tol, Vector3D* shift = 0); 154 | static void makeConventional(ISO& iso, double tol); 155 | 156 | // Print functions 157 | void print() const; 158 | void printComplete() const; 159 | static void printAll(); 160 | 161 | // Access functions 162 | const Word& itcNumber() const { return _itcNumber; } 163 | const Word& schoenflies() const { return _schoenflies; } 164 | const Word& hermannMauguinShort() const { return _hermannMauguinShort; } 165 | const Word& hermannMauguin() const { return _hermannMauguin; } 166 | const Word& hall() const { return _hall; } 167 | LatticeSystem system() const { return _system; } 168 | LatticeCentering centering() const { return _centering; } 169 | const OList& symmetry() const { return _symmetry; } 170 | const Matrix3D& unitToConv() const { return _unitToConv; } 171 | const Vector3D& originShift() const { return _originShift; } 172 | const OList& wyckoff() const { return _wyckoff; } 173 | const PointGroup& pointGroup() const { return _pointGroup; } 174 | }; 175 | 176 | 177 | 178 | #endif 179 | -------------------------------------------------------------------------------- /src/structureIO.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #include "structureIO.h" 24 | #include "mintStructure.h" 25 | #include "crystalMaker.h" 26 | #include "vasp.h" 27 | #include "findsym.h" 28 | #include "espresso.h" 29 | #include "json.h" 30 | #include "cif.h" 31 | #include "language.h" 32 | #include "output.h" 33 | 34 | 35 | 36 | /* StructureFormat StructureIO::getFormat(const Text& content) 37 | * 38 | * Get the format of a structure file 39 | */ 40 | 41 | StructureFormat StructureIO::getFormat(const Text& content) 42 | { 43 | 44 | // Check if mint 45 | if (MintStructure::isFormat(content)) 46 | return SF_MINT; 47 | 48 | // Check if cif 49 | if (CIF::isFormat(content)) 50 | return SF_CIF; 51 | 52 | // Check if vasp 4 53 | if (Vasp::Structure::isVersion4(content)) 54 | return SF_VASP4; 55 | 56 | // Check if vasp 5 57 | if (Vasp::Structure::isVersion5(content)) 58 | return SF_VASP5; 59 | 60 | // Check if quantum espresso 61 | if (Espresso::Files::isFormat(content)) 62 | return SF_ESPRESSO; 63 | 64 | // Return that type is not known 65 | return SF_UNKNOWN; 66 | } 67 | 68 | 69 | 70 | /* ISO StructureIO::read(const Text& content, StructureFormat format, double tol, double clusterTol) 71 | * 72 | * Read contents of structure file 73 | */ 74 | 75 | ISO StructureIO::read(const Text& content, StructureFormat format, double tol, double clusterTol) 76 | { 77 | switch (format) 78 | { 79 | case SF_MINT: 80 | return MintStructure::read(content, tol, clusterTol); 81 | case SF_CIF: 82 | return CIF::read(content, clusterTol); 83 | case SF_VASP4: 84 | return Vasp::Structure::read(content, false); 85 | case SF_VASP5: 86 | return Vasp::Structure::read(content, true); 87 | case SF_ESPRESSO: 88 | return Espresso::Files::read(content); 89 | default: 90 | Output::newline(ERROR); 91 | Output::print("Cannot read structure from file with unknown format"); 92 | Output::quit(); 93 | return ISO(); 94 | } 95 | } 96 | 97 | 98 | 99 | /* ISO StructureIO::read(const Word& file, double tol, double clusterTol) 100 | * 101 | * Read contents of structure file 102 | */ 103 | 104 | ISO StructureIO::read(const Word& file, double tol, double clusterTol) 105 | { 106 | 107 | // Get file contents 108 | Text content = Read::text(file); 109 | 110 | // Read structure 111 | return read(content, getFormat(content), tol, clusterTol); 112 | } 113 | 114 | 115 | 116 | /* void StructureIO::write(const Word& file, const ISO& iso, StructureFormat format, CoordinateType coordinates, 117 | * double tol) 118 | * 119 | * Write structure to file 120 | */ 121 | 122 | void StructureIO::write(const Word& file, const ISO& iso, StructureFormat format, CoordinateType coordinates, \ 123 | double tol) 124 | { 125 | switch (format) 126 | { 127 | case SF_MINT: 128 | MintStructure::write(file, iso, coordinates); 129 | break; 130 | case SF_CIF: 131 | CIF::write(file, iso, tol); 132 | break; 133 | case SF_VASP4: 134 | Vasp::Structure::write(file, iso, coordinates, false); 135 | break; 136 | case SF_VASP5: 137 | Vasp::Structure::write(file, iso, coordinates, true); 138 | break; 139 | case SF_CRYSTALMAKER: 140 | CrystalMaker::write(file, iso); 141 | break; 142 | case SF_FINDSYM: 143 | FindSym::write(file, iso, tol); 144 | break; 145 | case SF_ESPRESSO: 146 | Espresso::Files::write(file, iso, coordinates); 147 | break; 148 | case SF_JSON: 149 | JSON::write(file, iso); 150 | break; 151 | default: 152 | Output::newline(ERROR); 153 | Output::print("Cannot print to unknown format"); 154 | Output::quit(); 155 | } 156 | } 157 | 158 | 159 | 160 | /* Word StructureIO::structureFormat(StructureFormat format) 161 | * 162 | * Return the name of a format 163 | */ 164 | 165 | Word StructureIO::structureFormat(StructureFormat format) 166 | { 167 | switch (format) 168 | { 169 | case SF_AUTO: 170 | return Word("Automatic"); 171 | case SF_MINT: 172 | return Word("Mint"); 173 | case SF_CIF: 174 | return Word("CIF"); 175 | case SF_VASP4: 176 | return Word("VASP 4"); 177 | case SF_VASP5: 178 | return Word("VASP 5"); 179 | case SF_CRYSTALMAKER: 180 | return Word("CrystalMaker"); 181 | case SF_FINDSYM: 182 | return Word("FindSym"); 183 | case SF_ESPRESSO: 184 | return Word("Quantum Espresso"); 185 | case SF_JSON: 186 | return Word("JSON"); 187 | default: 188 | return Word("unknown"); 189 | } 190 | } 191 | 192 | 193 | 194 | /* StructureFormat StructureIO::structureFormat(const Words& words) 195 | * 196 | * Return the format of a file from name 197 | */ 198 | 199 | StructureFormat StructureIO::structureFormat(const Words& words) 200 | { 201 | 202 | // Loop over words in file 203 | for (int i = 0; i < words.length(); i++) 204 | { 205 | 206 | // Break if a comment 207 | if (Language::isComment(words[i])) 208 | break; 209 | 210 | // Found automatic 211 | if (words[i].equal("automatic", false, 4)) 212 | return SF_AUTO; 213 | 214 | // Found mint 215 | if ((words[i].equal("mint", false, 4)) || (words[i].equal(".mint", false, 5))) 216 | return SF_MINT; 217 | 218 | // Found CIF 219 | if ((words[i].equal("cif", false)) || (words[i].equal(".cif", false))) 220 | return SF_CIF; 221 | 222 | // Found vasp 223 | if ((words[i].equal("vasp", false)) || (words[i].equal(".vasp", false))) 224 | { 225 | 226 | // Check for vasp 4 227 | if (i < words.length() - 1) 228 | { 229 | if (words[++i] == "4") 230 | return SF_VASP4; 231 | } 232 | 233 | // Must be vasp 5 234 | return SF_VASP5; 235 | } 236 | 237 | // Found vasp 4 238 | if ((words[i].equal("vasp4", false)) || (words[i].equal(".vasp4", false))) 239 | return SF_VASP4; 240 | 241 | // Found vasp 5 242 | if ((words[i].equal("vasp5", false)) || (words[i].equal(".vasp5", false))) 243 | return SF_VASP5; 244 | 245 | // Found crystalMaker 246 | if ((words[i].equal("crystalmaker", false, 5)) || (words[i].equal("cm", false)) || \ 247 | (words[i].equal("cmtx", false)) || (words[i].equal(".cmtx", false))) 248 | return SF_CRYSTALMAKER; 249 | 250 | // Found findsym 251 | if ((words[i].equal("findsym", false)) || (words[i].equal(".findsym", false)) || \ 252 | (words[i].equal("fs", false)) || (words[i].equal(".fs", false))) 253 | return SF_FINDSYM; 254 | 255 | // Found quantum espresso 256 | if ((words[i].equal("quantum", false, 4)) || (words[i].equal("espresso", false, 3)) || \ 257 | (words[i].equal("qe", false)) || (words[i].equal(".qe", false))) 258 | return SF_ESPRESSO; 259 | 260 | // Found json 261 | if ((words[i].equal("json", false)) || (words[i].equal(".json", false))) 262 | return SF_JSON; 263 | } 264 | 265 | // Did not find a type 266 | return SF_UNKNOWN; 267 | } 268 | 269 | 270 | 271 | /* void StructureIO::addExtension(Word& word, StructureFormat format) 272 | * 273 | * Add extension 274 | */ 275 | 276 | void StructureIO::addExtension(Word& word, StructureFormat format) 277 | { 278 | switch (format) 279 | { 280 | case SF_MINT: 281 | word += ".mint"; 282 | break; 283 | case SF_CIF: 284 | word += ".cif"; 285 | break; 286 | case SF_VASP4: 287 | case SF_VASP5: 288 | word += ".vasp"; 289 | break; 290 | case SF_CRYSTALMAKER: 291 | word += ".cmtx"; 292 | break; 293 | case SF_FINDSYM: 294 | word += ".fs"; 295 | break; 296 | case SF_ESPRESSO: 297 | word += ".qe"; 298 | break; 299 | case SF_JSON: 300 | word += ".json"; 301 | break; 302 | default: 303 | break; 304 | } 305 | } 306 | -------------------------------------------------------------------------------- /src/structureIO.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef STRUCTUREIO_H 24 | #define STRUCTUREIO_H 25 | 26 | 27 | 28 | #include "iso.h" 29 | #include "text.h" 30 | #include "fileSystem.h" 31 | 32 | 33 | 34 | // Types of structure files 35 | enum StructureFormat {SF_UNKNOWN, SF_AUTO, SF_VASP4, SF_VASP5, SF_MINT, SF_CIF, SF_CRYSTALMAKER, SF_FINDSYM, \ 36 | SF_ESPRESSO, SF_JSON}; 37 | 38 | 39 | 40 | // Namespace for storing function to make ISO from file 41 | namespace StructureIO 42 | { 43 | 44 | // Test if a file is a structure 45 | StructureFormat getFormat(const Text& content); 46 | StructureFormat getFormat(const Word& file); 47 | 48 | // Read files 49 | ISO read(const Text& content, StructureFormat format, double tol = 1e-4, double clusterTol = 0.2); 50 | ISO read(const Text& content, double tol = 1e-4, double clusterTol = 0.2); 51 | ISO read(const Word& file, double tol = 1e-4, double clusterTol = 0.2); 52 | ISO read(const Word& file, StructureFormat format, double tol = 1e-4, double clusterTol = 0.2); 53 | 54 | // Write files 55 | void write(const Word& file, const ISO& iso, StructureFormat format, CoordinateType coordinates = FRACTIONAL, \ 56 | double tol = 1e-4); 57 | 58 | // Helper functions 59 | Word structureFormat(StructureFormat format); 60 | StructureFormat structureFormat(const Words& words); 61 | void addExtension(Word& word, StructureFormat format); 62 | } 63 | 64 | 65 | 66 | /* inline StructureFormat StructureIO::getFormat(const Word& file) 67 | * 68 | * Get file format 69 | */ 70 | 71 | inline StructureFormat StructureIO::getFormat(const Word& file) 72 | { 73 | return getFormat(Read::text(file)); 74 | } 75 | 76 | 77 | 78 | /* inline ISO StructureIO::read(const Text& content, double tol, double clusterTol) 79 | * 80 | * Get structure from file 81 | */ 82 | 83 | inline ISO StructureIO::read(const Text& content, double tol, double clusterTol) 84 | { 85 | return read(content, getFormat(content), tol, clusterTol); 86 | } 87 | 88 | 89 | 90 | /* inline ISO StructureIO::read(const Word& file, StructureFormat format, double tol, double clusterTol) 91 | * 92 | * Get structure from file 93 | */ 94 | 95 | inline ISO StructureIO::read(const Word& file, StructureFormat format, double tol, double clusterTol) 96 | { 97 | return read(Read::text(file), format, tol, clusterTol); 98 | } 99 | 100 | 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /src/text.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #include "text.h" 24 | 25 | 26 | 27 | // Buffer size for Word object 28 | int Word::_bufferSize = 8; 29 | 30 | // Stream buffer 31 | char Word::_buffer[100]; 32 | 33 | 34 | 35 | /* void Text::addLine(const char* line) 36 | * 37 | * Add line of text, breaking by spaces 38 | */ 39 | 40 | void Text::addLine(const char* line) 41 | { 42 | 43 | // Add new line 44 | addLine(); 45 | 46 | // Count the number of words in line 47 | int start = 0; 48 | int end = 0; 49 | int numWords = 0; 50 | while (getRange(start, end, end, line)) 51 | ++numWords; 52 | 53 | // Allocate space for words 54 | _text[_curLine].length(numWords); 55 | 56 | // Save words 57 | int i; 58 | start = 0; 59 | end = 0; 60 | while (getRange(start, end, end, line)) 61 | { 62 | 63 | // Allocate space in word 64 | _text[_curLine][++_curWord].length(end-start); 65 | 66 | // Save characters 67 | for (i = start; i < end; ++i) 68 | _text[_curLine][_curWord][i-start] = line[i]; 69 | } 70 | } 71 | 72 | 73 | 74 | /* void Text::split(char value) 75 | * 76 | * Split text at a given character 77 | */ 78 | 79 | void Text::split(char value) 80 | { 81 | 82 | // Loop over lines 83 | int i, j, k, m; 84 | Word temp; 85 | for (i = 0; i < _text.length(); ++i) 86 | { 87 | 88 | // Loop over words on line 89 | for (j = _text[i].length() - 1; j >= 0; --j) 90 | { 91 | 92 | // Loop over characters 93 | for (k = _text[i][j].length() - 1; k >= 0; --k) 94 | { 95 | 96 | // Found split character 97 | if (_text[i][j][k] == value) 98 | { 99 | 100 | // Value is at end of word 101 | if (k == _text[i][j].length() - 1) 102 | { 103 | 104 | // Value is only character in word 105 | if (k == 0) 106 | _text[i].remove(j); 107 | 108 | // Characters exist before 109 | else 110 | { 111 | _text[i][j].length(k); 112 | ++j; 113 | } 114 | } 115 | 116 | // Value is at beginning of word 117 | else if (k == 0) 118 | { 119 | 120 | // Save word 121 | temp = _text[i][j]; 122 | _text[i][j].set(1, temp.length() - 1, temp); 123 | } 124 | 125 | // Value occurs in middle of word 126 | else 127 | { 128 | 129 | // Save word 130 | temp = _text[i][j]; 131 | 132 | // Add word to line and move words back 133 | _text[i].add(); 134 | for (m = _text[i].length() - 1; m > j; --m) 135 | _text[i].swap(m, m - 1); 136 | 137 | // Set words 138 | _text[i][j].set(0, k, temp); 139 | _text[i][j+1].set(k+1, temp.length() - k - 1, temp); 140 | ++j; 141 | } 142 | 143 | // Break since found 144 | break; 145 | } 146 | } 147 | } 148 | } 149 | } 150 | 151 | 152 | 153 | /* bool Text::equal(const char* lhs, const char* rhs, bool caseMatters, int minToMatch) 154 | * 155 | * Return whether two char arrays are the same 156 | */ 157 | 158 | bool Text::equal(const char* lhs, const char* rhs, bool caseMatters, int minToMatch) 159 | { 160 | 161 | // Must match all characters 162 | if (!minToMatch) 163 | { 164 | 165 | // Check if characters are the same, including case 166 | if (caseMatters) 167 | { 168 | const char* itLHS; 169 | const char* itRHS; 170 | for (itLHS = lhs, itRHS = rhs; 1; itLHS++, itRHS++) 171 | { 172 | if (*itLHS != *itRHS) 173 | return false; 174 | if (*itLHS == '\0') 175 | break; 176 | } 177 | } 178 | 179 | // Check if characters are the same, ignoring case 180 | else 181 | { 182 | const char* itLHS; 183 | const char* itRHS; 184 | for (itLHS = lhs, itRHS = rhs; 1; itLHS++, itRHS++) 185 | { 186 | if (tolower(*itLHS) != tolower(*itRHS)) 187 | return false; 188 | if (*itLHS == '\0') 189 | break; 190 | } 191 | } 192 | } 193 | 194 | // Only the first set number of chacters need to match 195 | else 196 | { 197 | 198 | // Check if characters are the same, including case 199 | if (caseMatters) 200 | { 201 | int count = 0; 202 | const char* itLHS; 203 | const char* itRHS; 204 | for (itLHS = lhs, itRHS = rhs; 1; itLHS++, itRHS++) 205 | { 206 | if (*itLHS != *itRHS) 207 | return false; 208 | if ((++count == minToMatch) || (*itLHS == '\0') || (*itRHS == '\0')) 209 | break; 210 | } 211 | } 212 | 213 | // Check if characters are the same, ignoring case 214 | else 215 | { 216 | int count = 0; 217 | const char* itLHS; 218 | const char* itRHS; 219 | for (itLHS = lhs, itRHS = rhs; 1; itLHS++, itRHS++) 220 | { 221 | if (tolower(*itLHS) != tolower(*itRHS)) 222 | return false; 223 | if ((++count == minToMatch) || (*itLHS == '\0') || (*itRHS == '\0')) 224 | break; 225 | } 226 | } 227 | } 228 | 229 | // Return that words are the same if at this point 230 | return true; 231 | } 232 | 233 | 234 | 235 | /* bool Text::equal(const char* lhs, const char* rhs, bool caseMatters, int minToMatch, char ignore) 236 | * 237 | * Check if two words are equal, ignoring set character 238 | */ 239 | 240 | bool Text::equal(const char* lhs, const char* rhs, bool caseMatters, int minToMatch, char ignore) 241 | { 242 | 243 | // Must match all characters 244 | if (!minToMatch) 245 | { 246 | 247 | // Check if characters are the same, including case 248 | if (caseMatters) 249 | { 250 | const char* itLHS; 251 | const char* itRHS; 252 | for (itLHS = lhs, itRHS = rhs; 1; ++itLHS, ++itRHS) 253 | { 254 | while ((*itLHS == ignore) && (*itLHS != '\0')) 255 | ++itLHS; 256 | while ((*itRHS == ignore) && (*itRHS != '\0')) 257 | ++itRHS; 258 | if (*itLHS != *itRHS) 259 | return false; 260 | if (*itLHS == '\0') 261 | break; 262 | } 263 | } 264 | 265 | // Check if characters are the same, ignoring case 266 | else 267 | { 268 | const char* itLHS; 269 | const char* itRHS; 270 | for (itLHS = lhs, itRHS = rhs; 1; ++itLHS, ++itRHS) 271 | { 272 | while ((tolower(*itLHS) == ignore) && (*itLHS != '\0')) 273 | ++itLHS; 274 | while ((tolower(*itRHS) == ignore) && (*itRHS != '\0')) 275 | ++itRHS; 276 | if (tolower(*itLHS) != tolower(*itRHS)) 277 | return false; 278 | if (*itLHS == '\0') 279 | break; 280 | } 281 | } 282 | } 283 | 284 | // Only the first set number of chacters need to match 285 | else 286 | { 287 | 288 | // Check if characters are the same, including case 289 | if (caseMatters) 290 | { 291 | int count = 0; 292 | const char* itLHS; 293 | const char* itRHS; 294 | for (itLHS = lhs, itRHS = rhs; 1; ++itLHS, ++itRHS) 295 | { 296 | while ((*itLHS == ignore) && (*itLHS != '\0')) 297 | ++itLHS; 298 | while ((*itRHS == ignore) && (*itRHS != '\0')) 299 | ++itRHS; 300 | if (*itLHS != *itRHS) 301 | return false; 302 | if ((++count == minToMatch) || (*itLHS == '\0') || (*itRHS == '\0')) 303 | break; 304 | } 305 | } 306 | 307 | // Check if characters are the same, ignoring case 308 | else 309 | { 310 | int count = 0; 311 | const char* itLHS; 312 | const char* itRHS; 313 | for (itLHS = lhs, itRHS = rhs; 1; ++itLHS, ++itRHS) 314 | { 315 | while ((tolower(*itLHS) == ignore) && (*itLHS != '\0')) 316 | ++itLHS; 317 | while ((tolower(*itRHS) == ignore) && (*itRHS != '\0')) 318 | ++itRHS; 319 | if (tolower(*itLHS) != tolower(*itRHS)) 320 | return false; 321 | if ((++count == minToMatch) || (*itLHS == '\0') || (*itRHS == '\0')) 322 | break; 323 | } 324 | } 325 | } 326 | 327 | // Return that words are the same if at this point 328 | return true; 329 | } 330 | 331 | 332 | 333 | /* bool Text::contains(const char* text, const char* item, bool caseMatters) 334 | * 335 | * Check whether char array contains item 336 | */ 337 | 338 | bool Text::contains(const char* text, const char* item, bool caseMatters) 339 | { 340 | if (item == 0) 341 | return true; 342 | if (item[0] == '\0') 343 | return true; 344 | int i, j, k; 345 | for (i = 0; text[i] != '\0'; ++i) 346 | { 347 | if (((caseMatters) && (text[i] == item[0])) || \ 348 | ((!caseMatters) && (std::tolower(text[i]) == std::tolower(item[0])))) 349 | { 350 | for (j = 0, k = i; (item[j] != '\0') && (text[k] != '\0'); ++j, ++k) 351 | { 352 | if (caseMatters) 353 | { 354 | if (item[j] != text[k]) 355 | break; 356 | } 357 | else 358 | { 359 | if (std::tolower(item[j]) != std::tolower(text[k])) 360 | break; 361 | } 362 | } 363 | if (item[j] == '\0') 364 | return true; 365 | } 366 | } 367 | return false; 368 | } 369 | -------------------------------------------------------------------------------- /src/timer.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifdef MINT_MPI 24 | #include 25 | #endif 26 | #include "timer.h" 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | 34 | /* void Timer::start() 35 | * 36 | * Start the timer 37 | */ 38 | 39 | void Timer::start() 40 | { 41 | #ifdef MINT_MPI 42 | _start = MPI_Wtime(); 43 | #else 44 | timeval temptime; 45 | gettimeofday(&temptime, NULL); 46 | _start = temptime.tv_sec + temptime.tv_usec/1000000.0; 47 | #endif 48 | } 49 | 50 | 51 | 52 | /* double Timer::currentNumber() 53 | * 54 | * Return the current time 55 | */ 56 | 57 | double Timer::currentNumber() 58 | { 59 | #ifdef MINT_MPI 60 | return MPI_Wtime() - _start; 61 | #else 62 | timeval temptime; 63 | gettimeofday(&temptime, NULL); 64 | return temptime.tv_sec + temptime.tv_usec/1000000.0 - _start; 65 | #endif 66 | } 67 | 68 | 69 | 70 | /* Word Timer::current(bool formatTime, int precision) 71 | * 72 | * Return the current time 73 | */ 74 | 75 | Word Timer::current(bool formatTime, int precision) 76 | { 77 | 78 | // Get the current time 79 | double time = currentNumber(); 80 | 81 | // If printing as seconds only, then save and return 82 | Word res; 83 | char buffer[25]; 84 | if (!formatTime) 85 | { 86 | char set[10]; 87 | sprintf(set, "%s%d%s", "%.", precision, "f%s"); 88 | sprintf(buffer, set, time, " second"); 89 | res += buffer; 90 | if (fabs(time - 1) >= pow(10.0, -precision) - pow(10.0, -(precision + 4))) 91 | res += 's'; 92 | return res; 93 | } 94 | 95 | // Turn seconds into minutes 96 | int minutes = (int) floor(time / 60.0); 97 | double seconds = time - 60 * minutes; 98 | 99 | // Turn minutes into hours 100 | int hours = (int) floor(minutes / 60.0); 101 | minutes -= 60 * hours; 102 | 103 | // Turn hours into days 104 | int days = (int) floor(hours / 24.0); 105 | hours -= 24 * days; 106 | 107 | // Make into Word object 108 | if (days) 109 | { 110 | if (days == 1) 111 | sprintf(buffer, "%d%s", days, " day, "); 112 | else 113 | sprintf(buffer, "%d%s", days, " days, "); 114 | res += buffer; 115 | } 116 | if ((hours) || (days)) 117 | { 118 | if (hours == 1) 119 | sprintf(buffer, "%d%s", hours, " hour, "); 120 | else 121 | sprintf(buffer, "%d%s", hours, " hours, "); 122 | res += buffer; 123 | } 124 | if ((minutes) || (hours) || (days)) 125 | { 126 | if (minutes == 1) 127 | sprintf(buffer, "%d%s", minutes, " minute, "); 128 | else 129 | sprintf(buffer, "%d%s", minutes, " minutes, "); 130 | res += buffer; 131 | } 132 | char set[10]; 133 | sprintf(set, "%s%d%s", "%.", precision, "f%s"); 134 | sprintf(buffer, set, seconds, " second"); 135 | res += buffer; 136 | if (fabs(seconds - 1) >= pow(10.0, -precision) - pow(10.0, -(precision + 4))) 137 | res += 's'; 138 | 139 | // Return result 140 | return res; 141 | } 142 | -------------------------------------------------------------------------------- /src/timer.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef TIMER_H 24 | #define TIMER_H 25 | 26 | 27 | 28 | #include "text.h" 29 | 30 | 31 | 32 | // Class for timer functions 33 | class Timer 34 | { 35 | 36 | // Variables 37 | double _start; 38 | 39 | public: 40 | 41 | // Constructor 42 | Timer(bool startTimer = true) { if (startTimer) start(); } 43 | 44 | // Functions 45 | void start(); 46 | 47 | // Access functions 48 | double currentNumber(); 49 | Word current(bool formatTime, int precision); 50 | Word current(bool formatTime) { return current(formatTime, 4); } 51 | Word current(int precision) { return current(true, precision); } 52 | Word current() { return current(true, 4); } 53 | }; 54 | 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/unique.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef UNIQUE_H 24 | #define UNIQUE_H 25 | 26 | 27 | 28 | #include "iso.h" 29 | #include "symmetry.h" 30 | #include "text.h" 31 | #include "list.h" 32 | #include "num.h" 33 | 34 | 35 | 36 | // Class to find unique groups of atoms 37 | class Unique 38 | { 39 | 40 | // Class to store a single unique group 41 | class Group; 42 | 43 | // Variables 44 | OList::D2 _groups; 45 | 46 | // Settings variables 47 | bool _getEquivalent; 48 | bool _areTransitions; 49 | bool _useInterstitials; 50 | double _maxDistance; 51 | double _transPathRadius; 52 | double _voronoiTolerance; 53 | 54 | // Functions 55 | void initialize(); 56 | void generateGroup(Group curGroup, const ISO& iso, const Symmetry& symmetry, const OList& elements, \ 57 | int startGroup, int startIndex, double tol); 58 | void saveGroup(const Group& curGroup, const ISO& iso, const Symmetry& symmetry, double tol); 59 | bool isTransKnown(const Group& curGroup, const ISO& iso, const Symmetry& symmetry, double tol); 60 | bool isTransGood (const Group& curGroup, const ISO& iso, const Symmetry& symmetry, double tol); 61 | bool isGroupKnown(const Group& curGroup, const ISO& iso, const Symmetry& symmetry, double tol); 62 | void filterTransitions(const ISO& iso, const Symmetry& symmetry, double tol); 63 | void generateEquivalent(const ISO& iso, const Symmetry& symmetry, double tol); 64 | void saveGroup(const Group& curGroup, int set); 65 | bool isEquivTransKnown(const Group& curGroup, int set); 66 | bool isEquivGroupKnown(const Group& curGroup, int set); 67 | void sortGroups(); 68 | void sortGroup(int num, int left, int right); 69 | 70 | public: 71 | 72 | // Constructor 73 | Unique(); 74 | 75 | // Setup functions 76 | void search(const ISO& iso, const Symmetry& symmetry, OList elements, double tol); 77 | 78 | // Clear data 79 | void clear(); 80 | 81 | // Settings 82 | void getEquivalent (bool input) { _getEquivalent = input; } 83 | void areTransitions (bool input) { _areTransitions = input; } 84 | void useInterstitials (bool input) { _useInterstitials = input; } 85 | void maxDistance (double input) { _maxDistance = input; } 86 | 87 | // Other functions 88 | void print() const; 89 | Word makeISO(ISO& iso, int group) const; 90 | 91 | // Access functions 92 | const OList::D2& groups() const { return _groups; } 93 | }; 94 | 95 | 96 | 97 | // Class to store a single unique group 98 | class Unique::Group 99 | { 100 | 101 | // Variables 102 | List _atoms; 103 | List _distances; 104 | OList _vectors; 105 | 106 | // Functions 107 | bool isLess(const Group& rhs, int curNum) const; 108 | 109 | public: 110 | 111 | // Constructors 112 | Group() {} 113 | Group(const Group& rhs) { *this = rhs; } 114 | 115 | // Functions 116 | Group& operator= (const Group& rhs); 117 | bool operator< (const Group& rhs) const; 118 | 119 | // Access functions 120 | List& atoms() { return _atoms; } 121 | const List& atoms() const { return _atoms; } 122 | List& distances() { return _distances; } 123 | const List& distances() const { return _distances; } 124 | OList& vectors() { return _vectors; } 125 | const OList& vectors() const { return _vectors; } 126 | }; 127 | 128 | 129 | 130 | /* inline Unique::Unique() 131 | * 132 | * Constructor 133 | */ 134 | 135 | inline Unique::Unique() 136 | { 137 | initialize(); 138 | } 139 | 140 | 141 | 142 | /* inline void Unique::initialize() 143 | * 144 | * Set defaults 145 | */ 146 | 147 | inline void Unique::initialize() 148 | { 149 | _getEquivalent = false; 150 | _areTransitions = false; 151 | _useInterstitials = false; 152 | _maxDistance = -1; 153 | _transPathRadius = 0.25; 154 | _voronoiTolerance = 0.05; 155 | } 156 | 157 | 158 | 159 | /* inline void Unique::clear() 160 | * 161 | * Clear data 162 | */ 163 | 164 | inline void Unique::clear() 165 | { 166 | _groups.clear(); 167 | } 168 | 169 | 170 | 171 | /* inline void Unique::sortGroups() 172 | * 173 | * Sort groups 174 | */ 175 | 176 | inline void Unique::sortGroups() 177 | { 178 | for (int i = 0; i < _groups.length(); ++i) 179 | sortGroup(i, 0, _groups[i].length() - 1); 180 | } 181 | 182 | 183 | 184 | /* inline void Unique::sortGroup(int num, int left, int right) 185 | * 186 | * Quick sort of current group 187 | */ 188 | 189 | inline void Unique::sortGroup(int num, int left, int right) 190 | { 191 | 192 | // Current partition has no width 193 | if (left >= right) 194 | return; 195 | 196 | // Choose pivot index 197 | int pivotIndex = (left + right) / 2; 198 | Group pivot = _groups[num][pivotIndex]; 199 | 200 | // Move pivot to end 201 | _groups[num].swap(pivotIndex, right); 202 | 203 | // Iterate through current partition 204 | int newPivotIndex = left; 205 | for (int i = left; i < right; ++i) 206 | { 207 | if (_groups[num][i] < pivot) 208 | { 209 | _groups[num].swap(i, newPivotIndex); 210 | newPivotIndex++; 211 | } 212 | } 213 | 214 | // Move pivot to final position 215 | _groups[num].swap(newPivotIndex, right); 216 | 217 | // Recursive calls to next sorts 218 | sortGroup(num, left, newPivotIndex - 1); 219 | sortGroup(num, newPivotIndex + 1, right); 220 | } 221 | 222 | 223 | 224 | /* inline Unique::Group& Unique::Group::operator= (const Unique::Group& rhs) 225 | * 226 | * Assignment operator for unique group 227 | */ 228 | 229 | inline Unique::Group& Unique::Group::operator= (const Unique::Group& rhs) 230 | { 231 | if (this != &rhs) 232 | { 233 | _atoms = rhs._atoms; 234 | _vectors = rhs._vectors; 235 | _distances = rhs._distances; 236 | } 237 | return *this; 238 | } 239 | 240 | 241 | 242 | /* inline bool Unique::Group::operator< (const Unique::Group& rhs) const 243 | * 244 | * Test whether current group is less than another 245 | */ 246 | 247 | inline bool Unique::Group::operator< (const Unique::Group& rhs) const 248 | { 249 | return isLess(rhs, 0); 250 | } 251 | 252 | 253 | 254 | /* inline bool Unique::Group::isLess(const Unique::Group& rhs, int curNum) const 255 | * 256 | * Return whether current value in group is less than another 257 | */ 258 | 259 | inline bool Unique::Group::isLess(const Unique::Group& rhs, int curNum) const 260 | { 261 | if ((curNum >= _atoms.length()) || (curNum >= rhs._atoms.length())) 262 | return false; 263 | if (_atoms[curNum]->atomNumber() < rhs._atoms[curNum]->atomNumber()) 264 | return true; 265 | if (_atoms[curNum]->atomNumber() > rhs._atoms[curNum]->atomNumber()) 266 | return false; 267 | return isLess(rhs, curNum+1); 268 | } 269 | 270 | 271 | 272 | #endif 273 | -------------------------------------------------------------------------------- /src/vasp.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2014 Kyle Michel, Logan Ward, Christopher Wolverton 2 | * 3 | * Contact: Kyle Michel (kylemichel@gmail.com) 4 | * Logan Ward (LoganWard2012@u.northwestern.edu) 5 | * 6 | * 7 | * This file is part of Mint. 8 | * 9 | * Mint is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General 10 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Mint is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License along with Mint. If not, see 18 | * . 19 | */ 20 | 21 | 22 | 23 | #ifndef VASP_H 24 | #define VASP_H 25 | 26 | 27 | 28 | #include "iso.h" 29 | #include "elements.h" 30 | #include "text.h" 31 | #include "list.h" 32 | #include "fileSystem.h" 33 | 34 | 35 | 36 | // Namespace for VASP functionality 37 | namespace Vasp 38 | { 39 | 40 | // Classes 41 | class Job; 42 | class Structure; 43 | class Settings; 44 | class Potential; 45 | 46 | // Enumerated types 47 | enum Calculation {VC_NONE, VC_SINGLE, VC_RELAX_ALL, VC_RELAX_POSITIONS, VC_MD, VC_NEB, VC_CINEB}; 48 | enum Relaxation {VR_UNKNOWN, VR_QUASI_NEWTON, VR_CONJUGATE_GRADIENT, VR_DAMPED_MD}; 49 | enum Accuracy {VA_UNKNOWN, VA_HIGH, VA_NORMAL, VA_LOW}; 50 | enum Material {VM_UNKNOWN, VM_METAL, VM_INSULATOR}; 51 | enum IncarGroup {IG_UNKNOWN, IG_GENERAL, IG_ELECTRONIC, IG_ELECTRONIC_SMEARING, IG_ELECTRONIC_PROJECTORS, \ 52 | IG_ELECTRONIC_STARTUP, IG_ELECTRONIC_SPIN, IG_ELECTRONIC_EXCHANGE_CORRELATION, IG_ELECTRONIC_CONVERGENCE, \ 53 | IG_ELECTRONIC_CONVERGENCE_DETAIL, IG_ELECTRONIC_MIXER, IG_ELECTRONIC_MIXER_DETAILS, \ 54 | IG_ELECTRONIC_DIPOLE_CORRECTION, IG_GRIDS, IG_IONIC, IG_IONIC_MD, IG_SYMMETRY, IG_DOS, IG_WRITING, \ 55 | IG_PERFORMANCE, IG_MISCELLANEOUS, IG_OTHER, IG_VARIATIONAL_TRANSITION_STATE}; 56 | enum IncarTag {IT_UNKNOWN, IT_SYSTEM, IT_LCOMPAT, IT_PREC, IT_ENMAX, IT_ENAUG, IT_EDIFF, IT_ALGO, IT_IALGO, \ 57 | IT_IWAVPR, IT_NBANDS, IT_NELECT, IT_ISMEAR, IT_SIGMA, IT_LREA, IT_ROPT, IT_LMAXPAW, IT_LMAXMIX, IT_ISTART, \ 58 | IT_ICHARG, IT_INIWAV, IT_ISPIN, IT_LNONCOLLINEAR, IT_MAGMOM, IT_NUPDOWN, IT_LSORBIT, IT_SAXIS, IT_LSPIRAL, \ 59 | IT_QSPIRAL, IT_LZEROZ, IT_GGA, IT_VOSKOWN, IT_LASPH, IT_LMETAGGA, IT_GGA2, IT_NELM, IT_NELMDL, IT_NELMIN, \ 60 | IT_ENINI, IT_LDIAG, IT_WEIMIN, IT_EBREAK, IT_DEPER, IT_NRMM, IT_TIME, IT_AMIX, IT_BMIX, IT_AMIN, IT_AMIX_MAG, \ 61 | IT_BMIX_MAG, IT_IMIX, IT_MAXMIX, IT_WC, IT_INIMIX, IT_MIXPRE, IT_MREMOVE, IT_IDIPOL, IT_LDIPOL, IT_DIPOL, \ 62 | IT_EFIELD, IT_NGX, IT_NGY, IT_NGZ, IT_NGXF, IT_NGYF, IT_NGZF, IT_ADDGRID, IT_NSW, IT_IBRION, IT_ISIF, \ 63 | IT_PSTRESS, IT_EDIFFG, IT_NFREE, IT_POTIM, IT_SMASS, IT_TEBEG, IT_TEEND, IT_NBLOCK, IT_KBLOCK, IT_NPACO, \ 64 | IT_APACO, IT_ISYM, IT_SYMPREC, IT_LORBIT, IT_RWIGS, IT_NEDOS, IT_EMIN, IT_EMAX, IT_NWRITE, IT_LWAVE, \ 65 | IT_LCHARG, IT_LPARD, IT_LVTOT, IT_LELF, IT_LOPTICS, IT_STM, IT_NPAR, IT_NSIM, IT_NBLK, IT_LPLANE, \ 66 | IT_LCRITICAL_MEM, IT_LSCALAPACK, IT_LSCALU, IT_LASYNC, IT_IDIOT, IT_LMUSIC, IT_POMASS, IT_LCORR, IT_LREAL, \ 67 | IT_LREAL_COMPAT, IT_GGA_COMPAT, IT_LBERRY, IT_ICORELEVEL, IT_LDAU, IT_I_CONSTRAINED_M, IT_ICHAIN, IT_IMAGES, \ 68 | IT_SPRING, IT_LCLIMB, IT_LTANGENTOLD, IT_LDNEB, IT_NEBCELL, IT_IOPT, IT_NCORE}; 69 | 70 | // Functions 71 | Accuracy accuracy(const Word& word); 72 | Word accuracy(Accuracy accuracy); 73 | } 74 | 75 | 76 | 77 | // Vasp job 78 | class Vasp::Job 79 | { 80 | 81 | // Control variables 82 | bool _saveFiles; 83 | Calculation _calculation; 84 | Relaxation _relaxation; 85 | Accuracy _accuracy; 86 | Material _material; 87 | Word _executable; 88 | OList _elements; 89 | OList _potentials; 90 | 91 | // Variables to store results 92 | List _energy; 93 | List::D2 _convergence; 94 | OList::D2 _forces; 95 | ISO _structure; 96 | OList _structures; 97 | OList::D2 _tags; 98 | 99 | // Static member variables 100 | static bool _completed; 101 | static Word _dirName; 102 | static Word _prevDir; 103 | 104 | // Functions 105 | void writeFiles(const ISO& iso, bool restart); 106 | void writeNEBFiles(const OList& iso, bool restart); 107 | void gatherResults(); 108 | void gatherNEBResults(int numDirs); 109 | 110 | public: 111 | 112 | // Constructor and destructor 113 | Job(); 114 | 115 | // Setup functions 116 | void saveFiles(bool saveFiles) { _saveFiles = saveFiles; } 117 | void calculation(Calculation calculation) { _calculation = calculation; } 118 | void relaxation(Relaxation relaxation) { _relaxation = relaxation; } 119 | void accuracy(Accuracy accuracy) { _accuracy = accuracy; } 120 | void material(Material material) { _material = material; } 121 | void executable(const Word& executable) { _executable = executable; } 122 | void elements(const OList& elements) { _elements = elements; } 123 | void potentials(const OList& potentials) { _potentials = potentials; } 124 | void setTags(const OList::D2& tags) { _tags = tags; } 125 | 126 | // Functions 127 | bool submit(const ISO& iso, bool restart, bool quitIfError = true); 128 | bool submitNEB(const OList& iso, bool restart, bool quitIfError = true); 129 | 130 | // Access functions 131 | bool completed() const { return _completed; } 132 | const List& energy() const { return _energy; } 133 | const List::D2& convergence() const { return _convergence; } 134 | const OList::D2& forces() const { return _forces; } 135 | void updateStructure(ISO& iso) const; 136 | void updateStructures(OList& isos) const; 137 | }; 138 | 139 | 140 | 141 | // Vasp structure functions 142 | class Vasp::Structure 143 | { 144 | public: 145 | 146 | // Read structure 147 | static ISO read(const Text& content, bool useVasp5); 148 | static ISO read(const Word& file, bool useVasp5) { return read(Read::text(file), useVasp5); } 149 | 150 | // Write structure 151 | static void write(const Word& file, const ISO& iso, CoordinateType coordinates, bool useVasp5); 152 | 153 | // Check if file is in correct format 154 | static bool isVersion4(const Word& file) { return isVersion4(Read::text(file)); } 155 | static bool isVersion4(const Text& content); 156 | static bool isVersion5(const Word& file) { return isVersion5(Read::text(file)); } 157 | static bool isVersion5(const Text& content); 158 | }; 159 | 160 | 161 | 162 | // Vasp settings functions 163 | class Vasp::Settings 164 | { 165 | 166 | // Single setting 167 | struct Setting 168 | { 169 | bool forced; 170 | IncarGroup group; 171 | IncarTag tag; 172 | Word name; 173 | Word value; 174 | }; 175 | 176 | // Variables 177 | OList _settings; 178 | 179 | // Functions 180 | static bool match(const Word& name, IncarGroup* group, IncarTag* tag, const char* comp, IncarGroup compGroup, \ 181 | IncarTag compTag); 182 | void write(IncarGroup group, const char* header) const; 183 | 184 | // Default functions 185 | void generalDefaults(bool replaceExisting); 186 | void calculationDefaults(Calculation calculation, bool replaceExisting); 187 | void materialDefaults(Material material, bool replaceExisting); 188 | void accuracyDefaults(Accuracy accuracy, bool replaceExisting); 189 | 190 | public: 191 | 192 | // Constructor 193 | Settings() { defaults(VC_SINGLE, VR_QUASI_NEWTON, VM_METAL, VA_NORMAL); } 194 | 195 | // Setup functions 196 | void clear(); 197 | void defaults(Calculation calculation, Relaxation relaxation, Material material, Accuracy accuracy, \ 198 | const List* encut = 0); 199 | bool add(const Word& name, const Word& value, bool replaceExisting, bool forced = false); 200 | void remove(const Word& name); 201 | 202 | // Read and write functions 203 | void read(const Text& content); 204 | void read(const Word& file) { read(Read::text(file)); } 205 | bool isFormat(const Text& content); 206 | bool isFormat(const Word& file) { return isFormat(Read::text(file)); } 207 | void write(const Word& file) const; 208 | static bool isSetting(const Word& name, IncarGroup* group = 0, IncarTag* tag = 0); 209 | }; 210 | 211 | 212 | 213 | // Vasp potential 214 | class Vasp::Potential 215 | { 216 | public: 217 | static void write(const Word& file, const OList& elements, const OList& files, const ISO& iso, \ 218 | List* encut = 0); 219 | }; 220 | 221 | 222 | 223 | // ===================================================================================================================== 224 | // Job 225 | // ===================================================================================================================== 226 | 227 | /* inline Vasp::Job::Job() 228 | * 229 | * Constructor for vasp job 230 | */ 231 | 232 | inline Vasp::Job::Job() 233 | { 234 | _saveFiles = false; 235 | _calculation = VC_SINGLE; 236 | _relaxation = VR_CONJUGATE_GRADIENT; 237 | _accuracy = VA_NORMAL; 238 | _material = VM_METAL; 239 | } 240 | 241 | 242 | 243 | // ===================================================================================================================== 244 | // Settings 245 | // ===================================================================================================================== 246 | 247 | /* inline void Vasp::Settings::clear() 248 | * 249 | * Clear settings 250 | */ 251 | 252 | inline void Vasp::Settings::clear() 253 | { 254 | _settings.clear(); 255 | } 256 | 257 | 258 | 259 | #endif 260 | -------------------------------------------------------------------------------- /update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | 5 | # Name of directory to copy old files 6 | backupDir="backup" 7 | 8 | 9 | 10 | # Function to exit the script if something went wrong 11 | function exitFunction 12 | { 13 | echo "" 14 | echo "=====================================" 15 | echo "" 16 | echo "Update failed because "$1"." 17 | echo "" 18 | echo "Your old files are safe though and located in the directory \""$backupDir"\"." 19 | echo "" 20 | echo "You can download the source code manually in either of the following formats:" 21 | echo " Tarball: https://github.com/materials/mint/tarball/master" 22 | echo " Archive: https://github.com/materials/mint/archive/master.zip" 23 | echo "" 24 | exit 25 | } 26 | 27 | 28 | 29 | # Function to make a backup copy of files 30 | function backupFiles 31 | { 32 | echo "Creating \""$backupDir"\" directory and moving all files to it." 33 | origFiles=`ls` 34 | mkdir TEMPBACKUP 35 | for cur in $origFiles; do 36 | if [ $cur == "mint" ]; then 37 | cp $cur TEMPBACKUP 38 | echo " A copy of the \"mint\" executable was left in the current directory." 39 | elif [ $cur != "dlib" ]; then 40 | mv $cur TEMPBACKUP 41 | fi 42 | done 43 | mv TEMPBACKUP $backupDir 44 | } 45 | 46 | 47 | 48 | # Function to get tarball from github 49 | function getNewCode 50 | { 51 | echo "Downloading source code and other files from GitHub." 52 | wget --no-check-certificate -q https://github.com/materials/mint/tarball/master 2> /dev/null || \ 53 | curl -LOks https://github.com/materials/mint/tarball/master > /dev/null || \ 54 | exitFunction "tarball could not be downloaded from GitHub. Make sure that either \"wget\" or \"curl\" is available" 55 | if [ ! -e master ]; then 56 | exitFunction "source code was not downloaded correctly" 57 | fi 58 | } 59 | 60 | 61 | 62 | # Extract code from tarball 63 | function extractNewCode 64 | { 65 | echo "Extracting new files from the tarball that was downloaded." 66 | tar -xzf master || exitFunction "tarball extraction was not successful" 67 | if [ -e master ]; then 68 | rm -f master 69 | fi 70 | newDir="materials-mint"* 71 | if [ ${#newDir[@]} -eq 0 ]; then 72 | exitFunction " extracted directory was not found" 73 | fi 74 | mv $newDir/* . 75 | rm -fr $newDir 76 | } 77 | 78 | 79 | 80 | # Get dlib package 81 | function getDLIB 82 | { 83 | if [ ! -d "dlib" ]; then 84 | 85 | # Download the package 86 | echo "Downloading dlib package." 87 | wget -O dlib.tar.bz2 --no-check-certificate -q http://sourceforge.net/projects/dclib/files/latest/download 2> /dev/null || \ 88 | curl -Lks http://sourceforge.net/projects/dclib/files/latest/download 1> dlib.tar.bz2 2> /dev/null || \ 89 | exitFunction "dlib package could not be downloaded" 90 | 91 | # Unzip the directory and delete extra files 92 | mkdir dlib dlibTemp 93 | tar -xjf dlib.tar.bz2 -C dlibTemp 94 | mv dlibTemp/*/dlib/* dlib 95 | rm -fr dlibTemp dlib.tar.bz2 96 | fi 97 | } 98 | 99 | 100 | 101 | # Copy parameters from old makefile into new one 102 | function updateMakefile 103 | { 104 | 105 | # Makefile parameters and defaults 106 | makeParams=("CC" "g++" "OPT" "\-O3" "COMP" "\-c \-g" "LINK" "\-g" "BLAS" "\-lblas" "LAPACK" "\-llapack" \ 107 | "DEFINE" "" "MPIRUN" "\"mpirun \-np\"") 108 | 109 | # Get current values if previous makefile exists 110 | if [ -e $backupDir/Makefile ]; then 111 | echo "Saving previous Makefile settings." 112 | i=0; j=1 113 | while [ $i -lt ${#makeParams[@]} ]; do 114 | vars=(`grep ^${makeParams[$i]} $backupDir/Makefile | sed 's/:/ /' | sed 's/=/ /'`) 115 | if [ ${#vars[@]} -gt 0 ]; then 116 | if [ ${#vars[@]} -eq 1 ]; then 117 | makeParams[$j]='' 118 | elif [ ${vars[1]:0:1} != '#' ]; then 119 | makeParams[$j]=`echo ${vars[@]:1} | sed 's/\-/\\\-/g'` 120 | else 121 | makeParams[$j]='' 122 | fi 123 | fi 124 | i=`expr $i + 2`; j=`expr $j + 2` 125 | done 126 | 127 | # No Makefile existed 128 | else 129 | echo "Using default Makefile settings. Check these before compiling!" 130 | fi 131 | 132 | # Set values in Makefile 133 | i=0; j=1 134 | while [ $i -lt ${#makeParams[@]} ]; do 135 | sed 's/#'"${makeParams[$i]}"'#/'"${makeParams[$j]}"'/' < Makefile > temp 136 | mv temp Makefile 137 | i=`expr $i + 2`; j=`expr $j + 2` 138 | done 139 | } 140 | 141 | 142 | 143 | # Run update 144 | backupFiles 145 | getNewCode 146 | extractNewCode 147 | getDLIB 148 | updateMakefile 149 | echo "Update finished successfully. It should be safe to delete the directory \""$backupDir"\"." 150 | echo "Check \"Makefile\" and run \"make\" once you're ready to compile." 151 | --------------------------------------------------------------------------------