-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wish list for future versions of MULTEM #13
Comments
Is there a package already developed for conversion of the cif file into the text file that can be used for the MATLAB based simulation? |
I can provide a script that will do this, but it is written in python. |
Thanks a lot! That will be really helpful. |
I will upload it as soon as I'm home from work.
…On Wed, 10 Oct 2018, 18:50 Tara Prasad Mishra, ***@***.***> wrote:
Thanks a lot! That will be really helpful.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#13 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACmGj1TZ4cqvSvFjuQ_hZg9NgDNNf7brks5ujiVPgaJpZM4O8ubB>
.
|
Use at your own risk. It will convert cif and xyz files in whatever orientation they are in (c-axis faces the viewer after simulation). def save_cell_multem_txt(cif_cell, rms3d=0.085):
'''Convert cif file to the multem txt format
Can also take the xyz format as input (and really anything that ASE can take)
Requires the ASE Atomic Simulation Environment Python package
I recommend using Vesta (windows software) for manipulating
the cif file to enlarge it in the dimensions one wants
- use Edit -> Edit Data -> Unit Cell -> Transform.
The rms3d value is related to the debye-waller factor. It can
be given as a constant for all
atoms, or as a dict of {atomic_number:rms3d_value}.
It is a function of temperature, and can either be looked up in tables
or calculated by DFT
ie: (these are not real values) for carbon and zinc
rms3d = {
8:0.1,
30:0.09
}
Warning: There may be issues if the cif file has been rotated (by 90 degs). Check carefully.
'''
import numbers
import os
from pathlib import Path
import numpy as np
from ase.io import read
from scipy import io as out
filepath = Path(cif_cell)
name = filepath.stem
path = filepath.parent
cif_cell = read(cif_cell)
sample_x = cif_cell.cell[0,0]
sample_y = cif_cell.cell[1,1]
sample_z = cif_cell.cell[2,2]
lx = [sample_x]
ly = [sample_y]
dz = [sample_z/2] # Preferably some fraction of the unit cell, or just a small distance
header = [lx + ly + dz + 5*[0]]
occ = [1]
label = [0]
charge = [0]
if isinstance(rms3d, numbers.Number):
rms3d_list = [rms3d for Z in cif_cell.numbers]
else:
rms3d_list = [rms3d[Z] for Z in cif_cell.numbers]
data = [[n] + list(xyz) + [rms3d] + occ + label + charge for n, xyz, rms3d in zip(cif_cell.numbers, cif_cell.positions, rms3d_list)]
total = np.array(header + data)
np.savetxt(path / (name + ".txt"), total, fmt='%.8f', newline="\n", delimiter=" ") |
Thank you. This works wonderfully well to generate an .txt file, which can be used in the MULTEM GUI. How do we use this script to generate the crystal by layers which can be used to generate the crystals as shown in the crystalline_materials so that we can use it in the MULTEM Matlab version? |
My apologies, when I read "text file" in your first post, my brain assumed that you meant for the gui version, despite your clarification at the end. I will upload the version for matlab as well in a bit. In terms of building the crystal, I recommend doing that in either ASE or Vesta, and exporting it as a .xyz file and then converting it using my scripts. I explained some of this in the docstring in the above function. |
As I'm now remembering things (a little while since I wrote the scripts): Multem (Matlab) creates a crystalline sample based on some unit cell. That wasn't enough for me, since I wanted to build some larger and more complicated structures (think defected cells, grain boundaries etc). Therefore I bypass the loading mechanism in the matlab version, and load a matlab |
If you just want to create the equivalent of the Au001Crystal(), but for your material, I suggest you just duplicate a file in crystalling_materials, and then edit it to produce your own crystal. For the cases of cubic, tetragonal and orthorhombic crystals, this is not hard. I am not sure how one would approach it for a non-orthogonal crystal. |
def save_cell_multem(cif_cell, rms3d=0.085):
'''Convert cif file to the multem matlab format
Requires a `load(cif_cell.mat)` code in matlab, and should overwrite any a b c, spec_atoms etc.
Can also take the xyz format as input (and really anything that ASE can take)
Requires the ASE Atomic Simulation Environment Python package
I recommend using Vesta (windows software) for manipulating
the cif file to enlarge it in the dimensions one wants
- use Edit -> Edit Data -> Unit Cell -> Transform.
The rms3d value is related to the debye-waller factor. It can
be given as a constant for all
atoms, or as a dict of {atomic_number:rms3d_value}.
It is a function of temperature, and can either be looked up in tables
or calculated by DFT
ie: (these are not real values) for carbon and zinc
rms3d = {
8:0.1,
30:0.09
}
Warning: There may be issues if the cif file has been rotated (by 90 degs). Check carefully.
'''
import numbers
import os
from pathlib import Path
import numpy as np
from scipy import io as out
from ase.io import read
filepath = Path(cif_cell)
name = filepath.stem
path = filepath.parent
cif_cell = read(cif_cell)
occ = [1]
label = [0]
charge = [0]
if isinstance(rms3d, numbers.Number):
rms3d_list = [rms3d for Z in cif_cell.numbers]
else:
rms3d_list = [rms3d[Z] for Z in cif_cell.numbers]
data = [[Z] + list(xyz) + [rms3d_list[Z]] +
occ + label + charge for Z, xyz in zip(cif_cell.numbers, cif_cell.positions)]
sample_x = cif_cell.cell[0, 0]
sample_y = cif_cell.cell[1, 1]
sample_z = cif_cell.cell[2, 2]
matlabdict = {
"spec_atoms": data,
"spec_lx": sample_x,
"spec_ly": sample_y,
"spec_lz": sample_z,
"spec_dz": sample_z/4, # Preferably some fraction of the unit cell, or just a small distance
"a": sample_x,
"b": sample_y,
"c": sample_z,
}
out.savemat(os.path.join(path, name), matlabdict) Below is an example multem matlab script that loads the above output correctly. It also supports having vacuum around the edges, if that should be of interest. |
Wonderful! Thank you so much. The python script and the stem example scripts were beautiful. Previously all my attempts had resulted in MATLAB crashing altogether. The only changes I had to make was material specific. I sincerely hope the above example and the python code could be included in the original MULTEM package. This would greatly help new learners. |
I didn't notice this before, whenever I am converting a .cif file to the corresponding .mat file the number of atoms that are generated in the spec_atoms variables is 112. The actual atoms were about 64. (both the .cif and .mat file obtained after the conversion are attached). |
How odd. Let me take a look. |
So with that giant post out of the way - how are you generating your cif files? |
I am generating my .cif files using virtual nano lab. |
This is a draft. For when I remember them, I thought I'd write a little wish list for future versions of MULTEM.
Hopefully these are things that I can help with in the coming weeks/months:
output_multislice
, and how best to save them.The text was updated successfully, but these errors were encountered: