ml-evs / matador

⚗️ matador is an aggregator, manipulator and runner of first-principles calculations, written with a bent towards battery 🔋 electrode materials.
https://matador-db.readthedocs.io
MIT License
29 stars 19 forks source link

Projected Band Structure with Materials Studio CASTEP files #32

Closed sajidurehman closed 4 years ago

sajidurehman commented 4 years ago

Hi Dear Matthew Evans, I hope you would be fine and enjoying good health. I have a little query regarding projected band structure. Is it possible to use Matador code for Materials Studio based CASTEP band structure files (.bands and .cell) for projected band structure. Thank you in advance.

Looking forward to hear you.

Best Regards Sajid (PhD Student)

ml-evs commented 4 years ago

Hi Sajid,

I don't think there's any reason why you can't perform the same calculation with MS (I have never used it) but you will not get the same automation. If you can perform a normal bandstructure calculation with the CASTEP keyword PDOS_CALCULATE_WEIGHTS: true, then you should get a .pdos_bin file at the end of the calculation. You will then need to use a recent version of [OptaDOS] (https://github.com/optados-developers/optados) (normally bundled with CASTEP) to post-process the calculation with a similar .odi input file as found in the matador tutorial. This should leave you with a .bands, .cell, .pdos_bin and a .pdis.dat file, which you can plot using the dispersion script in this repository.

It may also interest you that itself CASTEP has a new license that makes it free for all academics worldwide (http://www.castep.org/CASTEP/GettingCASTEP) which would allow you to use some of the other features in this package (but you would have to compile your own copy of CASTEP).

I'm going to close this issue, but I'll stay subscribed so feel free to ask questions and continue the discussion below.

sajidurehman commented 4 years ago

Hi Matthew Evans, Thank you so much for kind reply. As per you guidance , i tried Si2 example. First i performed the PDOS calculations in MS and obtained the Si2.pdos_bin. Then trying to use the optados code. but i am facing an issue in optados. Please see following error. "OptaDOS: Execution started on 7 May 2020 at 15:36:46 Exiting....... Error: Problem opening ome_bin file in read_band_optical_mat"

Could you please guide me how to fix this error. Looking forward to hear you again

ml-evs commented 4 years ago

No problem! Just so we're on the same page, do you mean this example?

https://github.com/optados-developers/optados/tree/develop/optados/examples/Si2_PDIS

It looks like MS isn't creating one of the files that optados is expecting. Which version of MS are you running, and do you know which version of CASTEP is running underneath (it should say in the .castep file)?

sajidurehman commented 4 years ago

Thank you for prompt reply. No i am talking about following example

https://github.com/optados-developers/optados/tree/develop/optados/examples/Si2_DOS

I am running MS 2017 and about CASTEP version i am not so sure but i find following information " This version was compiled for x86_64-windows-msvc2008 on May 05 2016" i didnt find any other information regarding CASTEP version.

ml-evs commented 4 years ago

Did you use the same cell and param file with MS as used in that example? I'm afraid I don't quite understand how MS works with CASTEP input files.

For that example, you would need to run a DOS calculation rather than a bandstructure.

sajidurehman commented 4 years ago

Yes, i copied .cell and .param files from that example and performed the calculations. So, MS used the .param parameters and performed the calculations. Please see attachment you will know the input and output of MS calculation. Thank you in advance for you time and guidance.

Si2 CASTEP.zip

ml-evs commented 4 years ago

I've just tried running the example from your input files and I can confirm that I do get the .dome_bin file out of the calculation with CASTEP 20, so I'm afraid this looks like an MS problem that I can't help out with.

As I mentioned earlier, you might have some more luck if you can get access to CASTEP itself, otherwise you'll have to go through MS's support system. Sorry I can't help any more!

ml-evs commented 4 years ago

This link might help though (note ome_bin is listed): https://www.tcm.phy.cam.ac.uk/castep/documentation/WebHelp/content/modules/castep/expcastepfileformats.htm

It might also just be a case of updating MS, if you can do that!

sajidurehman commented 4 years ago

Hi Matthew Evans, Thank you so much for your valuable sugguestions and time. I will go for CASTEP academics license. Once again thank you.

sajidurehman commented 4 years ago

Hi Matthew Evans, Sorry to disturb you again. Luckily, MS 2017 also have same file formats (Please see ome_bin is also listed) as MS 2020. image

One more thing, when i perfomed only optical properties calculation then obtained .ome_bin. particularly not on DOS/PDOS calculations. Then, why optados require ome.bin file for DOS calculation?

Besides this when tried to run following example

https://github.com/ml-evs/matador/tree/develop/examples/bandstructure%2Bdos/simple

I got the following error. could you please let me know how to fix this error. command: dispersion LiCoO2-CollCode29225 --png -gw 0.01

Traceback (most recent call last): File "/home/max/.local/bin/dispersion", line 8, in sys.exit(main()) File "/home/max/.local/lib/python3.6/site-packages/matador/cli/dispersion.py", line 172, in main **kwargs File "/home/max/.local/lib/python3.6/site-packages/matador/plotting/plotting.py", line 44, in wrapped_plot_function from tkinter import TclError ModuleNotFoundError: No module named 'tkinter'

ml-evs commented 4 years ago

That's strange, I'm afraid I'm not sure why. My CASTEP version produced the .ome_bin when just performing a DOS.

For the matador query, it looks like you need to install the extra dependencies required for plotting. You can either do this with pip install .[plotting] from inside the matador folder, or by just installing matplotlib directly with pip install matplotlib (both those commands assume you are in the correct Python environment).

sajidurehman commented 4 years ago

Hi Matthew Evans, I tried both commands pip install .[plotting] and pip install matplotlib. Both are successfully run. But still facing same error. Is there any issue besides these dependencies?

ml-evs commented 4 years ago

Tkinter should be installed on almost all machines, could you tell me what OS you are using? If it does not work for you then I can release a quick patch.

sajidurehman commented 4 years ago

Hi Matthew Evans, I am using ubuntu 18.04.3 LTS.

ml-evs commented 4 years ago

Could you reinstall matador from the branch ml-evs/fix_tcl_error and tell me if that works?

ml-evs commented 4 years ago

I've just created #36 to track this.

sajidurehman commented 4 years ago

Sorry, i am not much fimilar with programs/ code. So, as per my understanding I again downloaded matador from here and installed. I dont know either its a right way or not. But again facing same error.

ml-evs commented 4 years ago

There are installation instructions here: https://docs.matador.science/en/latest/install.html

It might be worth doing pip uninstall matador first to make sure you have a clean environment.

Immediately after step 1 in this case, you should do an extra step:

git checkout ml-evs/fix_tcl_error

and then continue installing matador.

sajidurehman commented 4 years ago

Thank you for all setps. I have followed your steps and successfully again installed matador. Now error gone but getting following message.The obtained figure is blank there is no graph in it.

"Loading perhaps unsuitable defaults instead."

ml-evs commented 4 years ago

The defaults message isn't anything to worry about but I'm confused about the plot. We've gone quite far down the rabbithole in this issue, would you mind opening a new one providing your input files and exactly what command you are trying to execute?

sajidurehman commented 4 years ago

Now i got my mistake. Thank you so much for help and time.

ml-evs commented 4 years ago

I'll merge the TclError fix if that worked for you. I'm hoping to release as a PyPI package soon so installing will be much easier in future.

sajidurehman commented 4 years ago

Yes, TclError fix solved my problem. Yes, that's great news if PyPI package available.

sajidurehman commented 4 years ago

Hi Sajid,

I don't think there's any reason why you can't perform the same calculation with MS (I have never used it) but you will not get the same automation. If you can perform a normal bandstructure calculation with the CASTEP keyword PDOS_CALCULATE_WEIGHTS: true, then you should get a .pdos_bin file at the end of the calculation. You will then need to use a recent version of [OptaDOS] (https://github.com/optados-developers/optados) (normally bundled with CASTEP) to post-process the calculation with a similar .odi input file as found in the matador tutorial. This should leave you with a .bands, .cell, .pdos_bin and a .pdis.dat file, which you can plot using the dispersion script in this repository.

It may also interest you that itself CASTEP has a new license that makes it free for all academics worldwide (http://www.castep.org/CASTEP/GettingCASTEP) which would allow you to use some of the other features in this package (but you would have to compile your own copy of CASTEP).

I'm going to close this issue, but I'll stay subscribed so feel free to ask questions and continue the discussion below.

Hi Matthew Evans, As you guided me to plot projected-bandstructures we only need .bands, .cell, .pdos_bin and a .pdis.dat files. As per your guidance, I put all four files for Si in same directory and then tried to excute disperion --bs Si but i got following error.

Traceback (most recent call last): File "/home/max/.local/bin/dispersion", line 8, in sys.exit(main()) File "/home/max/.local/lib/python3.6/site-packages/matador/cli/dispersion.py", line 174, in main *kwargs File "/home/max/.local/lib/python3.6/site-packages/matador/plotting/plotting.py", line 84, in wrapped_plot_function raise exc File "/home/max/.local/lib/python3.6/site-packages/matador/plotting/plotting.py", line 80, in wrapped_plot_function result = function(args, **kwargs) File "/home/max/.local/lib/python3.6/site-packages/matador/plotting/spectral_plotting.py", line 211, in plot_spectral ax_dispersion = dispersion_plot(seeds, ax_dispersion, kwargs, bbox_extra_artists) File "/home/max/.local/lib/python3.6/site-packages/matador/plotting/spectral_plotting.py", line 367, in dispersion_plot _add_path_labels(seeds[-1], dispersion, ax_dispersion, path, 0, kwargs) File "/home/max/.local/lib/python3.6/site-packages/matador/plotting/spectral_plotting.py", line 833, in _add_path_labels if key in doc and key + '_labels' in doc: TypeError: argument of type 'IndexError' is not iterable

Could you please guide me more how to fix this error. Please find the required files in attachment. Si.zip

Best Regards Sajid

ml-evs commented 4 years ago

Hi Sajid, looks like a bit of a misleading error message. The problem is actually the blank %block species_pot block in your cell file, either delete it or add your pseudopotential information and the plot will work.

sajidurehman commented 4 years ago

Thank you so much for prompt reply and guiding me in the right direction. Now I got the plot. 1) Is it possible to use the different color for different elements and projectors. If you see the attached figure Si(s) and Si(p) almost have same colour. image

2) How to change the range along the y-axis like does dispersion has option of ymin or ymax?

Best Regards Sajid

ml-evs commented 4 years ago
  1. Is it possible to use the different color for different elements and projectors. If you see the attached figure Si(s) and Si(p) almost have same colour.

This is currently only possible through the Python API; if you re-run OptaDOS with pdispersion: ang then the projectors will be coloured according to your default matplotlib colour cycle (or the matador one by default if you have left the style unchanged). I could change it so that the case of a single element from a species_ang calculation also uses the default colour scheme, rather than the element-based colour scheme.

  1. How to change the range along the y-axis like does dispersion has option of ymin or ymax?

dispersion Si --plot_window -10 2 will set the plot window to (-10, 2) (Fermi level at 0).

There are currently a few bugs outstanding in the spectral plotter that I am hoping to fix over the coming days, so I may make the tweak at the end of point 1. soon anyway.

ml-evs commented 4 years ago

I've just made a pull request (#94) that improves spectral plotting. Once it's merged, you will be able to use --projector_colours red blue green orange etc. to override the colour palette. I don't have time to add any proper element/orbital configuration options, but hopefully this is good enough for your purposes. PDIS plots should also be much faster to create, and will export as PDF much more easily with rasterization.

sajidurehman commented 4 years ago

Thank you so much for this great feature. It will be very benificial for new learners like me. Again thank you so much for this great code.

ml-evs commented 4 years ago

No problem! You might also be interested in the sumo code which is built for this kind of plotting, I think they have some support for CASTEP now too (https://github.com/SMTG-UCL/sumo)

sajidurehman commented 4 years ago

Thank you for suggestion! I have seen before sumo, but sumo couldn't offer projected band strucrure feature like matador. Moreover, sumo did't deal with the optados generated files. Personally, i like the optados high quality DoS and Pdispersion features. So, If matador offer sumo like plotting features It will be more good.