art blog(derogatory)

Janaina Medeiros
Sweet Seals For You, Always
trying on a metaphor

shark vs the universe
No title available

祝日 / Permanent Vacation
todays bird
almost home
occasionally subtle

blake kathryn

Product Placement
RMH

roma★
let's talk about Bridgerton tea, my ask is open
noise dept.
No title available
wallacepolsom

No title available
TVSTRANGERTHINGS
seen from United States

seen from Türkiye

seen from Türkiye
seen from Italy
seen from Bolivia
seen from Colombia
seen from Ireland

seen from United States
seen from Lithuania

seen from Colombia
seen from Colombia
seen from Malaysia
seen from United States
seen from United States
seen from United States

seen from United States

seen from United States

seen from United States
seen from United States
seen from Chile
@ankoor-blog
What is a block?
A block is simply the chunk of code between do- end or curly braces.
Here’s a block using do- end:
Here’s a block using curly braces:
What is a Proc?
A Proc, short for procedure, is also a chunk of code.
The syntax for a proc looks like this:
How are...
The Pace of Productivity - how to master your creative routine.
Super options
class Mammal def spine spine = true end def initialize(options = {}) @sex = options{:sex} end end class Human < Mammal def initialize(options={}) @arms = options{:arms} @legs = options{:legs} super options end end
On a personal note, I won’t be with my computer awhile.
Rubular is a Ruby-based regular expression editor and tester. It's a handy way to test regular expressions as you write them. Rubular is an especially good fit for Ruby and Rails developers, since it uses Ruby on the server to evaluate regexes, but should also be useful for those working in other programming languages and frameworks (Java, PHP, Python, Javascript, etc.)
Useful methods on arrays
select
group_by
each_cons
cycle
reject
detect
each_with_index
Mutating variable types in Ruby
to_c → complex
Returns a complex which denotes the string form. The parser ignores leading whitespaces and trailing garbage. Any digit sequences can be separated by an underscore. Returns zero for null or garbage string.
to_f → float
Returns the result of interpreting leading characters in str as a floating point number. Extraneous characters past the end of a valid number are ignored. If there is not a valid number at the start of str, 0.0 is returned. This method never raises an exception.
to_i(base=10) → integer
Returns the result of interpreting leading characters in str as an integer base base (between 2 and 36). Extraneous characters past the end of a valid number are ignored. If there is not a valid number at the start of str, 0 is returned. This method never raises an exception when base is valid.
to_r → rational
Returns a rational which denotes the string form. The parser ignores leading whitespaces and trailing garbage. Any digit sequences can be separated by an underscore. Returns zero for null or garbage string.
to_s → str
to_str → str
Returns the receiver.
to_str → str
Returns the receiver.
to_sym → symbol
Returns the Symbol corresponding to str, creating the symbol if it did not previously exist. See Symbol#id2name.
Debugging in Ruby
PRY, its simple and easy
require pry
require pry-debugger
put 'binding.pry' in your code
And sample code to add error messages and a switch for 'debug' mode
#setup debugging debug = false def say(message) puts message if debug end
# enter a debug message say('message')
Cruft
The dust that gathers underneath a bed
Shoddily constructed or made
Bad code
Accumulated physical or virtual junk.
Ruby shells
irb and pry
irb seems nice but pry comes with tab completion and syntax highlighting :o
https://www.ruby-toolbox.com/categories/irb_Alternatives
irb can be customised witg a ~/.irbrc file and can handle tab completion and colours with a few lines,
require 'irb/completion' require 'wirble'
irb config file :https://gist.github.com/patmcnally/893833
Transferring HUGE files
by compressing, splitting, transferring, recombining and decompressing
Compress and split into 70Mbyte chucks
tar -zcvf - <stuff to put in archive> | split --bytes=70m --suffix-length=4 --numeric-suffix - myarchive.tar.gz
recombine and decompress
cat myarchive.tar.* | tar -zxvf -
Running linux commands in the background
Use ‘&’ to make a copy command like ‘cp A B’, complete in the background. So you’d run ‘cp A B&’
Python scripts and ASE for Materials Simulation
EVQ calculations
EVQ, calculations refer to the volume correction method outlined by Bruneval and Crocombette:
REF: F. Bruneval and J. P. . P. Crocombette, Phys. Rev. B 86(14), 140103 (2012).
Setup EVQ corrections
>> aseroutines.setup_dvol_corrections_evq
will create input files for EVQ corrections on defect volumes. It reads the vasp simulation from the current working directory and creates input files for volumes, 99% 100% and 101%. Plus it edits the INCAR file to make NSW =0 and LVTOT = .TRUE.
A submit script and submission must be done manually.
Make sure to use a version of VASP that includes the XC-potential in the LOCPOT file.
read_average_LOCPOT – will parse the LOCPOT file and return the average potential. Should also work with CHGCAR files and other similarly formatted VASP files.
Get EVQ correction
Used with the Setup EVQ function
>> aserountines.get_EVQ_data():
This parses the EVQ simulations as made by aseroutines.setup_dvol_corrections_evq and gives back the required pressure correction to calculate defect volumes. Ref: Bruneval
Subroutine: Edit LOCPOT file to get EVQ parameters
>> aserountines.edit_LOCPOT_file(filename)
Removes a spurious set of lines between potential tables for major and minor spins so ASE will read it correctly
get spin density data and plots
>> aserountines.get_spin_density_file(filename)
This routine will edit a normal CHGCAR so VESTA can read it and plot the spin density.
The spin density table is the “spin_up – spin_down” table included in the standard CHGCAR. However, the current version of VESTA will just ignore it.
Get distances between atoms and an atom or coordinate
>> aserountines.output_distances_to_point(atoms,a,b,c)
>> aserountines.output_distances_to_atom(atoms,atom)
These write out text files containing lattice parameters, lattice matrix and the distances from a specified atom/coordinate to each other atom.
Extract POSCAR for just the local tetrahedra and defect
>> aserountines.output_ZnOX_positions(atoms)
This gives a POSCAR containing just the defect and its tetrahedral in the ZnOX-332C cell. The script is specific to the DFT+U simulations of the ZnOX project.
It can be easily edited to use other atom numbers or use an arbitrary list of atom numbers
Notes on using Atomistic Simulation Environment (ASE)
Building cells
Building a unit cell is easily done with the crystal function in ase.lattice.spacegroup.
Unit cells
The following create a ZnO wurtzite cell, (spacegroup 186).
a =3.25
c = 5.204
x = (1./3)
zno = crystal(['Zn','O'], basis=[(0,0,0), (x,2*x,0)],spacegroup=186, cellpar=[a,a,c,90,90,120])
and here are the properties of the new cell object, ‘zno’:
In [44]: zno.get_chemical_symbols()
Out[44]: ['Zn', 'Zn', 'O', 'O']
In [42]: zno.get_scaled_positions()
Out[42]:
array([[ 0. , 0. , 0. ],
[ 0. , 0. , 0.5 ],
[ 0.33333333, 0.66666667, 0. ],
[ 0.66666667, 0.33333333, 0.5 ]])
In [45]: zno.get_cell()
Out[45]:
array([[ 3.25000000e+00, 0.00000000e+00, 0.00000000e+00],
[ -1.62500000e+00, 2.81458256e+00, 0.00000000e+00],
[ 3.18653097e-16, 5.51923354e-16, 5.20400000e+00]])
Supercells
the cell object for a 3x3x2 supercell can be made by using the ‘size=()’ option
zno = crystal(['Zn','O'], basis=[(0,0,0), (x,2*x,0)],spacegroup=186, size=(3,3,2), cellpar=[a,a,c,90,90,120])
Import a POSCAR file
read an existing POSCAR with,
zno332 = ase.io.read(‘FILENAME’,format=’vasp’)
and various formats are acceptable including .cif files, CASTEP files and vasp CONTCAR, POSCAR and OUTCAR files.
Splicing and manipulating cells
Splicing two cells and/or extending one cell can be done by manipulating and recombining cell objects. Lets start with getting the atomic positions for a 112 supercell by replicating and translating the atomic positions of a unit cell.
This gets the fractional positions and rescales them for a new 112 supercell
In[X]:positions112 = numpy.vstack((zno.get_scaled_positions(), (zno.get_scaled_positions()+[0,0,1]) ))
In[X]: positions112 = positions112*[1,1,0.5]
Use hstack to create a correctly arranged list of atoms
In[X]:atoms112 = numpy.hstack((zno.get_chemical_symbols(), zno.get_chemical_symbols() ))
In[X]:atoms112 = numpy.hstack((zno.get_atomic_numbers(), zno.get_atomic_numbers() ))
The 1x1x2 cell lattice is,
cell112=zno.get_cell()*[1,1,2]
Put it all together by making the cell with the ASE Atoms library;
cell112 = Atoms(symbols=atoms112,cell=cell112)
and add atoms:
cell112.set_scaled_positions(positions112)
cell112.set_atomic_numbers(atoms112)
-OR, depending on what you sourced earlier -
cell112.set_chemical_symbols(atoms112)
And, finally write out a POSCAR file,
In[X]: ase.io.write(‘FILE_NAME’, cell_object, format=’vasp’)
You can use ase.io.write(...., vasp5=True) for the vasp5 format.
Cell parameters
Cell parameters from a vasp run, in the abc-αβγ format:
This creates an array of cell parameters from a cell orientated across the horizontal axis :
abc = numpy.sqrt(numpy.sum(__CELL-OBJECT__.get_cell()**2,axis=1))
When the cell matrix is orientated across the vertical axis, use the ‘axis=2 option’
The angles, in degrees are:
gamma = numpy.degrees( arccos( numpy.dot( znoVzn.get_cell()[0:1], znoVzn.get_cell()[1:2].T) /
( (numpy.linalg.norm(znoVzn.get_cell()[0:1]) *
(numpy.linalg.norm(znoVzn.get_cell()[1:2])
) ) ) ) )
code for CELL PARAMETERS:
>> abc = numpy.sqrt(numpy.sum(cell.get_cell()**2,axis=1))
>> alpha = numpy.float64( numpy.degrees ( arccos( numpy.dot( cell.get_cell()[2:3], cell.get_cell()[1:2].T) / ((numpy.linalg.norm(cell.get_cell()[2:3]) *(numpy.linalg.norm(cell.get_cell()[1:2]))))) ))
>> beta = numpy.float64( numpy.degrees ( arccos( numpy.dot( cell.get_cell()[0:1], cell.get_cell()[2:3].T) / ((numpy.linalg.norm(cell.get_cell()[0:1]) *(numpy.linalg.norm(cell.get_cell()[2:3]))))) ))
>> gamma = numpy.float64( numpy.degrees ( arccos( numpy.dot( cell.get_cell()[0:1], cell.get_cell()[1:2].T) / ((numpy.linalg.norm(cell.get_cell()[0:1]) *(numpy.linalg.norm(cell.get_cell()[1:2]))))) ))
[abc[0], abc[1], abc[2], alpha, beta, gamma]
This has been implemented as a function in asetools.py. Use asteools.cellparam(__ATOMS_OBJECT__) to get the abc cell parameters.
Restart old calculation
To continue an old calculation which has been performed without the interface use the restart parameter when constructing the calculator
>>> calc = ase.calculators.vasp.Vasp(restart=True)
Then the calculator will read atomic positions from the CONTCAR file, physical quantities from the OUTCAR file, k-points from theKPOINTS file and parameters from the INCAR file.
Note: Only Monkhorst-Pack and Gamma-centered k-point sampling are supported for restart at the moment. Some INCARparameters may not be implemented for restart yet. Please report any problems to the ASE mailing list.
The restart parameter can be used , as the name suggest to continue a job from where a previous calculation finished. Furthermore, it can be used to extract data from an already performed calculation. For example, to get the total potential energy of the sodium chloride molecule in the previous section, without performing any additional calculations, in the directory of the previous calculation do:
>>> calc = Vasp(restart=True)
>>> atoms = calc.get_atoms()
>>> atoms.get_potential_energy() -4.7386889999999999