Skip to content
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

Add colorbar to the multiple xyz overlay plot #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

petrusen
Copy link

@petrusen petrusen commented Sep 19, 2024

Hi Sebastian,

I’ve added a colorbar to facilitate the interpretation of the plot that arises from:

python3 xyzoverlay.py multi-mol_trj.xyz -aa -vcm -cm coolwarm -ee H

the new feature should appear by just adding the keyboard -cb True:

python3 xyzoverlay.py multi-mol_trj.xyz -aa -vcm -cm coolwarm -cb True -ee H

otherwise I think that it was not completely clear how many structures were considered in the plot. In my specific case, it is interesting to know how many steps did it take to optimize the molecular structure with quantum mechanics. Besides, it also helps to point towards the first and last structure, which could be a bit confusing without a color reference.

I hope it may be of interest and let me know if any adjustments are needed!

Best,
Enric

@radi0sus
Copy link
Owner

Hi Enric,

now I got the FutureWarning regarding Downcasting again. Uncommenting pd.set_option("future.no_silent_downcasting", True) removes it. Otherwise your addition is nice. However, it works only good for a large number of molecules where the number of colors is equal or the number of molecules is larger than the number of colors in the colormap. Try it with two or three molecules to check what I mean.

Best,
Sebastian

@petrusen
Copy link
Author

Hi Sebastian,

As far as I can tell, it was related to how the **xyz_df_list ** was constructed. The total number of xyz was always minus one.

Instead, if the following function is employed to construct the same list, the issue is solved, and one can get a plot where two and three xyz have different colors.

Let me know if you find it useful.
Best,
Enric

image
image

def read_xyz_to_dataframe(file_path):
    """
    Given a text file with concatenated xyz coordinates, the function generates
    a list of panda objects for each xyz.
    """

    with open(file_path, 'r') as file:
        lines = file.readlines()
    data = []
    i = 0
    while i < len(lines):
        # Number of atoms (first line)
        num_atoms = int(lines[i].strip())
        i += 1
        # Second line (energy or other information)
        i += 1
        # Temporal list for every xyz
        data2 = []
        # Extract atomic coordinates
        for _ in range(num_atoms):
            line = lines[i].split()
            element = line[0]
            x, y, z = map(float, line[1:4])
            data2.append([element, x, y, z])
            i += 1
        # List of xyz
        data.append(data2)

    # Now convert it to list of pd objects
    xyz_df_list = list()
    columns = ["element", "x", "y", "z"]
    for structure in data:
        xyzdata = structure
        df = pd.DataFrame(xyzdata, columns=columns)
        xyz_df_list.append(df)

    return xyz_df_list

xyz_df_list = read_xyz_to_dataframe(args.filename[0])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants