andreww / elastic-constants Goto Github PK
View Code? Open in Web Editor NEWScripts to calculate elastic properties from a set of strained structures
License: Other
Scripts to calculate elastic properties from a set of strained structures
License: Other
The primary use of this script is as an alternative, Open, back-end to Materials Studio's 'Calculate Elastic Constants' feature. It was designed with CASTEP in mind, and only deals with the set of strains that Materials Studio generates. As well as CASTEP's native formats, it also accepts input in CML format, and can generate CML output. It also has the option to generate an at-a-glance view, which allows the user to verify the success, or otherwise, of all of the various linear fits. It should be fairly easy to convert/generalize it for other strains and simulation codes. Supported Strain Patterns ------------------------- Cubic: e1+e4 Hexagonal: e3 and e1+e4 Trigonal-High (32, 3m, -3m): e1 and e3+e4 Trigonal-Low (3, -3): e1 and e3+e4 Tetragonal: e1+e4 and e3+e6 Orthorhombic: e1+e4 and e2+e5 and e3+e6 Monoclinic: e1+e4 and e3+e6 and e2 and e5 Triclinic: e1 to e6 separately Dependencies ------------ The script is written in Python, so you must have that installed. I use Python 2.5, but earlier versions might work too. SciPy (http://www.scipy.org/) (Optional) For CML input/output, you'll need Golem (http://www.lexical.org.uk/golem/), and lxml (http://codespeak.net/lxml/). (Optional) For graphical output, you'll need Matplotlib (http://matplotlib.sourceforge.net/).
What happens if there if there were pre-existing constrains in the cell (i.e. a cell_constrains block)? Should they should be removed when creating the new .cell files with the conflicting keyword FIX_ALL_CELL or is this meaningless (as the zero strain cell won't be at energy minimum).
Should automate the test cases, and tell it not to check results to arbitrary precision (5-8 dp is enough).
As reported by email - this needs investigation but I'm adding it here so I don't forget
The version check at line 254 of elastics.py is not robust on recent systems (where scipy reports version strings line '0.12.0'. Should probably just calculate the error ourselves everywhere, or check our calculated error against scipy's and issue a warning if they differ.
If the user supplies a lattice type to generate_strain (with the -l option) the code fails with an undefined variable error. This is the "suptype" variable, that should be user-settable. See modifications in Josh's tree as a starting point.
It does not run with python 3! Shouldn't be too hard to fix (just print statements, I think).
Seems we can now get CASTEP to create a cell file - worth investigating if this is useful (we currently parse this information from the .castep output). See:
By the way, the way I would normally recommend to extract an optimized geometry from a castep run is to set the parameter
write_cell_structure : true
which will write a new .cell file with the co-ordinates at high precision. By comparison "castep2cell" loses precision as it can only
extract the number of significant digits printed in the .castep file.
I discovered an issue when using a castep.castep file for which lattice parameters have been held fixed. Normally of course when using CASTEP's internal geometry optimization this wouldn't be the case. However if one performed the geometry optimization instead using a grid-based approach (a grid of different lattice parameters), and then did a final run relaxing atom positions but keeping lattice vectors fixed, then one might have a .castep file like this.
Currently the code assumes the .castep corresponds to a geometry optimization run. I.e., 'Unit Cell' is looked for after 'Final Configuration:'. However if a grid-based approach is used there is no 'Unit Cell' after 'Final Configuration'. Of course in this case any 'Unit Cell' will do, as they are all the same (unchanged over the simulation).
I didn't see any guidance on contributions to this code so I've included a fix for this here. If you agree with the change perhaps you could incorporate it into your codebase?:
Change to castep.py:
After:
dotcastep_latt_RE = ...
add:
#New regular expression targeting just the 'Unit Cell' section
dotcastep_latt_fixed_RE = re.compile(r"""\s+Unit\sCell\s*\n\s+-+\s*\n
\s+Real\sLattice(A)\s+Reciprocal\sLattice(1/A)\s*\n
\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s*\n
\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s*\n
\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s+([+-]?\d+.\d+)\s*\n""", re.VERBOSE)
The start of parse_dotcastep should then read:
def parse_dotcastep(seedname):
"""
Extract lattice and atom positions from a .castep
file. List of atoms may be empty (e.g. MgO)
"""
dotCastep = open(seedname+".castep","r")
# Find the lattice. First attempt to locate 'Final Configuration' followed by 'Unit Cell'
latticeblock = dotcastep_latt_RE.findall(dotCastep.read()) # Get the last block - handle concat restarts
if latticeblock:
print("Lattice block identified after 'Final Configuration'")
latticeblock = latticeblock[-1]
else:
print("No 'Unit Cell' after 'Final Configuration' - assuming fixed lattice relaxation.")
# If 'Unit Cell' does not proceed 'Final Configuration', unit cell parameters may have been fixed (using
# FIX_ALL_CELL in .cell file). This may occur e.g. if a grid method was used to optimize geometry followed
# by a fixed lattice parameter relaxation. In this case rewind and look instead just for 'Unit Cell'
dotCastep.seek(0)
latticeblock = dotcastep_latt_fixed_RE.findall(dotCastep.read())[-1]
lattice = []
...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.