romerogroup / pyprocar

A Python library for electronic structure pre/post-processing
GNU General Public License v3.0
172 stars 76 forks source link

Getting data #159

Open HeejuKim95 opened 3 months ago

HeejuKim95 commented 3 months ago

Hello, developers,

I want to extract data using pyprocar and then use another visualization tool (such as gnuplot) to plot the graph. So, I coded as below to extract the data and create a new file with x, y, colorweight, and other necessary data. However, the third column (probably the color weights) keeps getting rounded to two decimal places. I need it to be rounded to three decimal places. How can I adjust this to get three decimal places?

Also, why does the third column show all zeros when I use the parametric method?

Thank you in advance, Heeju

Ca_s = pyprocar.bandsplot(
                code='vasp',
                mode='scatter',
                atoms=Ca,
                orbitals=s,
                elimit=[-4,4],
                knames=['$\\Gamma$','K','M','$\\Gamma$'],
                cmap='Blues',
                dirname=data_dir,
                clim = (0.0, 0.5),
                title='Ca s')

fig, ax = Ca_s

with open(data_dir + '/Ca_s.dat', 'w') as f:

    for collection in ax.collections:
        offsets = collection.get_offsets()  
        values = collection.get_array()    

        for (x, y), value in zip(offsets, values):
            if float(x) == 0:
                f.write('\n\n')
                f.write(f'{x:.8f} {y:.8f} {value:.8f}\n')
            else:
                f.write(f'{x:.8f} {y:.8f} {value:.8f}\n')
lllangWV commented 3 months ago

Hey,

so this is similar to another issue. Another user wanted the density of states values so they could plot the values using another software. Getting the exact data from the matplotlib.axes object can be a little confusing. Looking at your code, I can't see why this is happening. The solution to this was to collect all the data before plotting and export it to a desired format (json,txt,json,dat).

I can't get to this right now, but I will try to in the next couple days. I will update you if I have made some progress.

Logan Lang

lllangWV commented 3 months ago

Hey,

I added an option to bandsplot that will export data to (csv,json,dat,txt) file.

pyprocar.bandsplot(
                    code=code,
                    mode='scatter',
                    fermi=5.3017,
                    orbitals = [4,5,6,7,8],
                    export_data_file=os.path.join(current_dir,'data.dat'),
                    dirname=data_dir)

Here, is what the files look like: image

The first column are the kpath values, the second is the kpath tick names, and then the rest of the columns are alternating bands and and projection value columns.

I also found why you were only getting 2 decimals in your code. We rounded the values to 2 decimals for scatter mode. I removed this, so your code should work now.

If you need anything else or if you want me to modify output formats, let me know.

Best,

Logan Lang

HeejuKim95 commented 3 months ago

Thank you so much for your quick help. How can I download the modified version of pyprocar that you worked on?

I downloaded pyprocar using the command: git clone https://github.com/romerogroup/pyprocar.git

But I’m encountering the following error: AttributeError: module 'pyprocar' has no attribute 'bandsplot'

What could I be doing wrong?

lllangWV commented 3 months ago

That looks correct. Without more details I have no idea what is wrong.

Here are the commands I would use. I make sure pyprocar is uninstall from pip, then install it from the github repo.

pip uninstall pyprocar
git clone git@github.com:romerogroup/pyprocar.git
cd pyprocar
pip install -e .

Let me know if this works.

Logan Lang

HeejuKim95 commented 3 months ago

I followed your instructions, but I'm still facing the issue.

When I run the following code:

import pyprocar
import os
print(dir(pyprocar))

I get the output: ['__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

However, when I run the same code after installing pyprocar with pip install pyprocar, I get: ['BandStructure2DHandler', 'FermiHandler', 'Parser', 'ProcarParser', 'Settings', '__author__', '__builtins__', '__cached__', '__copyright__', '__date__', '__doc__', '__email__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__status__', '__version__', 'abinit', 'autobandsplot', 'bandgap', 'bandsdosplot', 'bandsplot', 'bxsf', 'cat', 'cfg', 'core', 'dftbplus', 'dosplot', 'download_dev_data', 'download_example', 'download_examples', 'elk', 'fermi2D', 'filter', 'frmsf', 'generate2dkmesh', 'io', 'kpath', 'lobster', 'parser', 'plotter', 'procarparser', 'pyposcar', 'qe', 'repair', 'scriptAutoBandsplot', 'scriptBandGap', 'scriptBandStructure2DHandler', 'scriptBandsDosplot', 'scriptBandsplot', 'scriptCat', 'scriptDosplot', 'scriptFermi2D', 'scriptFermiHandler', 'scriptFilter', 'scriptKmesh2D', 'scriptKpath', 'scriptRepair', 'scriptSpin_asymmetry', 'scriptUnfold', 'scripts', 'siesta', 'spin_asymmetry', 'unfold', 'utils', 'vasp', 'version', 'welcome']

It seems like something isn't being installed correctly.

Heeju

ahromero commented 3 months ago

Ummm it is hard to follow what you have done but you have to check your installation. It is not a problem of PyProcar.

Check if you do not have different python installations or packages with different versions… that happens if you install python using different sources (conda, miniconda, etc). With the lines you wrote, I was able to install it (for two different machines) with no problem raised. Sorry we cannot help much if your python installation has a problem.

__::::__ Prof. Aldo Humberto Romero Director Research Computing, West Virginia University Eberly Family Distinguished Professor Fellow American Physical Society Editor Physica B, Assistant Editor EPJB, Editor Frontiers in Physics Section Editor Papers in Physics Member of the Editorial Board of “Materials” and “Symmetry Physics” https://scholar.google.com/citations?user=pwte-hQAAAAJ&hl=en

Physics and Astronomy Department West Virginia University 135 Willey Street, PO Box 6315 111 White Hall Morgantown, WV 26506 Phone: 304-293-6317 Fax: 304-293-5732 email: @.***

From: HeejuKim95 @.> Date: Thursday, August 15, 2024 at 10:16 AM To: romerogroup/pyprocar @.> Cc: Subscribed @.***> Subject: Re: [romerogroup/pyprocar] Getting data (Issue #159)

I followed your instructions, but I'm still facing the issue.

When I run the following code:

import pyprocar

import os

print(dir(pyprocar))

I get the output: ['doc', 'file', 'loader', 'name', 'package', 'path', 'spec']

However, when I run the same code after installing pyprocar with pip install pyprocar, I get: ['BandStructure2DHandler', 'FermiHandler', 'Parser', 'ProcarParser', 'Settings', 'author', 'builtins', 'cached', 'copyright', 'date', 'doc', 'email', 'file', 'loader', 'name', 'package', 'path', 'spec', 'status', 'version', 'abinit', 'autobandsplot', 'bandgap', 'bandsdosplot', 'bandsplot', 'bxsf', 'cat', 'cfg', 'core', 'dftbplus', 'dosplot', 'download_dev_data', 'download_example', 'download_examples', 'elk', 'fermi2D', 'filter', 'frmsf', 'generate2dkmesh', 'io', 'kpath', 'lobster', 'parser', 'plotter', 'procarparser', 'pyposcar', 'qe', 'repair', 'scriptAutoBandsplot', 'scriptBandGap', 'scriptBandStructure2DHandler', 'scriptBandsDosplot', 'scriptBandsplot', 'scriptCat', 'scriptDosplot', 'scriptFermi2D', 'scriptFermiHandler', 'scriptFilter', 'scriptKmesh2D', 'scriptKpath', 'scriptRepair', 'scriptSpin_asymmetry', 'scriptUnfold', 'scripts', 'siesta', 'spin_asymmetry', 'unfold', 'utils', 'vasp', 'version', 'welcome']

It seems like something isn't being installed correctly.

Heeju

— Reply to this email directly, view it on GitHubhttps://github.com/romerogroup/pyprocar/issues/159#issuecomment-2291349346, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AB24DTPOHBQ73I3FMD36T2TZRSZ25AVCNFSM6AAAAABMKUXXBSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJRGM2DSMZUGY. You are receiving this because you are subscribed to this thread.Message ID: @.***>

lllangWV commented 3 months ago

Yes,

follow what ahromero, by checking the installations and pacakges.

I would advise to do a fresh install. Here, I create a virtual environment to make sure python isn't using the default interpreter, which might have the error.

conda create -n pyporcar python==3.9
conda activate pyprocar
git clone git@github.com:romerogroup/pyprocar.git
cd pyprocar
pip install -e .

I just did this, and it is working for me.

Best,

Logan Lang

HeejuKim95 commented 3 months ago

Thanks! I think the problem was that I kept installing and uninstalling, leaving behind some cache or remnants. I tried again in a new environment, and it worked!

I'm already very pleased with the export_data_file option you provided. However, I think it could be improved if the output format were slightly different. Since gnuplot, a widely used visualization tool, plots graphs based on columns, it would be more convenient for more people if the data were organized with the kpath values in the first column, band energy in the second column, and weight in the third column.

Anyway, I've solved all my problems, so thank you very much!

Heeju

ahromero commented 3 months ago

Thanks for your suggestion… I think you can easily generate a script to modify the output to the most convenient form for you…

__::::__ Prof. Aldo Humberto Romero Director Research Computing, West Virginia University Eberly Family Distinguished Professor Fellow American Physical Society Editor Physica B, Assistant Editor EPJB, Editor Frontiers in Physics Section Editor Papers in Physics Member of the Editorial Board of “Materials” and “Symmetry Physics” https://scholar.google.com/citations?user=pwte-hQAAAAJ&hl=en

Physics and Astronomy Department West Virginia University 135 Willey Street, PO Box 6315 111 White Hall Morgantown, WV 26506 Phone: 304-293-6317 Fax: 304-293-5732 email: @.***

From: HeejuKim95 @.> Date: Thursday, August 15, 2024 at 12:04 PM To: romerogroup/pyprocar @.> Cc: Aldo Romero @.>, Comment @.> Subject: Re: [romerogroup/pyprocar] Getting data (Issue #159)

Thanks! I think the problem was that I kept installing and uninstalling, leaving behind some cache or remnants. I tried again in a new environment, and it worked!

I'm already very pleased with the export_data_file option you provided. However, I think it could be improved if the output format were slightly different. Since gnuplot, a widely used visualization tool, plots graphs based on columns, it would be more convenient for more people if the data were organized with the kpath values in the first column, band energy in the second column, and weight in the third column.

Anyway, I've solved all my problems, so thank you very much!

Heeju

— Reply to this email directly, view it on GitHubhttps://github.com/romerogroup/pyprocar/issues/159#issuecomment-2291607891, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AB24DTMCNXUCATVOPVM3OUDZRTGRRAVCNFSM6AAAAABMKUXXBSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJRGYYDOOBZGE. You are receiving this because you commented.Message ID: @.***>

cardenas97 commented 2 months ago

Dear all,

Following up on your previous discussion, is there any way I can obtain the information on the orbital-projected 2D Fermi surface so that I can plot it using scattered points to properly identify each orbital contribution? Please find attached a reference picture of my goal.

image

I've tried some options but still no success. Please find attached a picture of my current projected orbitals

image

Thank you for your time, Best.

lllangWV commented 2 months ago

Hey Cardenas97,

Apologies for the delayed response—my graduate school workload has been ramping up.

Just to confirm, you're asking for the data in a similar format to what is discussed earlier, correct?

For the plots, we first identify the contours and then interpolate the projection values onto the surface. When plotting, we use LineCollection from Matplotlib to draw the contour lines.

I can provide you with the points that define the contours along with the interpolated projection values. Would this format work for you? I can deliver the data in CSV, JSON, or DAT format. For example, in CSV, the columns would represent the points per band contour, followed by the projection values per band.

If this doesn't meet your needs, you would have to extract the data directly from the matplotlib.axes object.

Best regards,
Logan

cardenas97 commented 2 months ago

Dear Logan,

Thank you for your response. Yes, I would appreciate it if you could provide the interpolated points in a .csv or .dat file, with each column representing an orbital. That way, I can plot the data myself using scatter points, as you suggested.

I also wanted to take the opportunity to ask you something about my current project. I am trying to plot the 2D projected orbitals onto the 2D Fermi surface of a tetragonal system (a = b ≠ c) at k_z = 0 . However, when I attempt to rotate the system using the command rotation = [90, 1, 1, 0], it does not work, and I receive an interpolation error:

'''' While executing: | qhull d Qc Qt Qbb Q12 Qz Options selected for Qhull 2019.1.r 2019/06/21: run-id 1234757170 delaunay Qcoplanar-keep Qtriangulate Qbbound-last Q12-allow-wide Qz-infinity-point _pre-merge _zero-centrum Qinterior-keep Pgood _max-width 1.3 Error-roundoff 9.1e-16 _one-merge 6.4e-15 Visible-distance 1.8e-15 U-max-coplanar 1.8e-15 Width-outside 3.6e-15 _wide-facet 1.1e-14 _maxoutside 7.3e-15

precision problems (corrected unless 'Q0' or an error) 1 degenerate hyperplanes recomputed with gaussian elimination 1 nearly singular or axis-parallel hyperplanes

The input to qhull appears to be less than 3 dimensional, or a computation has overflowed.

Qhull could not construct a clearly convex simplex from points:

Best, Jorge

lllangWV commented 2 months ago

Thank you for your response. Yes, I would appreciate it if you could provide the interpolated points in a .csv or .dat file, with each column representing an orbital. That way, I can plot the data myself using scatter points, as you suggested.

I will work on this.

I also wanted to take the opportunity to ask you something about my current project. I am trying to plot the 2D projected orbitals onto the 2D Fermi surface of a tetragonal system (a = b ≠ c) at k_z = 0 . However, when I attempt to rotate the system using the command rotation = [90, 1, 1, 0], it does not work, and I receive an interpolation error:

I am able to reproduce this error, this issue is being cause by degenerate points in the x,y plane. In our code we create a mesh grid for the x and y directions because we assume these are in-plane.

x, y = self.kpoints[:, 0], self.kpoints[:, 1]
# and new, interpolated component
xmax, xmin = x.max(), x.min()
ymax, ymin = y.max(), y.min()
self.log.debug("xlim = " + str([xmin, xmax]) + "  ylim = " + str([ymin, ymax]))
xnew, ynew = np.mgrid[
xmin : xmax : interpolation * 1j, ymin : ymax : interpolation * 1j
        ]

The reason why this happens is due to the system being tetragonal (no orthogonal axes) and the rotation. Currently, I do not know how to solve this issue. I will have to talk to some of the other developers on this.

Another possible solution is to use the Fermi3D implementation and use the cross section slicer.

The reason for the rough surface is due to the lack of points. This is solvable by increasing the kmesh and/or use the interpolation_factor=2. You will probably need a denser mesh, a 9 9 11 grid is not very dense.

fermiHandler = pyprocar.FermiHandler(
                                    code="vasp",
                                    dirname=data_dir,
                                    apply_symmetry=True)

fermiHandler.plot_fermi_cross_section(
                              slice_normal=(1,1,0),
                              slice_origin=(0,0,0),
                              cross_section_slice_linewidth=5.0,
                              mode="parametric",
                              orbitals=orbitals,
                              interpolation_factor=1,
                              save_2d_slice=f'{data_dir}/image.png',
                              atoms=atoms,
                              show=True,)

image

image

You will need to download the main branch from git for this.

pip uninstall pyprocar
git clone git@github.com:romerogroup/pyprocar.git
cd pyprocar
pip install -e .

Best,

Logan Lang

cardenas97 commented 2 months ago

Dear Logan,

Thank you for your suggestions. They worked very well and matched the expected results from other studies. I hope I can also extract the orbital projections as suggested in our previous messages.

Best, Jorge