DanPorter / Dans_Diffraction

Reads crystallographic cif files and simulates diffraction
Apache License 2.0
45 stars 13 forks source link

inter-atomic distance search #14

Closed Prestipino closed 3 months ago

Prestipino commented 7 months ago

Few modifications to add the possibility to search inter-atomic distances

changing:

minor changing:

DanPorter commented 6 months ago

Dear @Prestipino, Thank you once again for your modifications to Dans_Diffraction! Apologies for the delay but I wanted to take my time reading through your code.

Your additions of functions_general.distance2plane and indexing for Crystal.Atoms['site'] are very welcome!

I'm still trying to understand the code for interatomic distances. There is very similar functionality in Crystal.Properties.atomic_neighbours although perhaps it lacks some features. I think similar output could be generated using the following code - is this correct?

def atom_distances(xtl, max_d=3.20):
    distances = {}
    for site in xtl.Atoms:
        # atomic_neighbours uses the index from xtl.Structure
        structure_index = next(n for n, lab in enumerate(xtl.Structure.label) if lab == site.label)
        rel_pos, label = xtl.Properties.atomic_neighbours(structure_index, radius=max_d)
        distances[site.label] = {
            'dist': fg.mag(rel_pos[1:]),  # 1st position is always the central atom
            'label': label[1:],
        }
    return distances

Possibly Properties.atomic_neighbours needs some work to make it more useful! Anyway, would you mind moving your Crystal.search_distances to the Properties class for consistency?

Prestipino commented 6 months ago

Dear @Dan Sorry for the late reply, my fault, I haven't noticed Crystal.Properties.atomic_neighbours. In reality, I was wondering for a while if not to place the search distance in properties. I think is better to integrate the previous method with more features. I'll do asap and we discuss the final code cheers Carmelo

DanPorter commented 6 months ago

Hi @Prestipino, I've just committed (maybe I should have pushed to your branch?) a change to classes_properties.py with a new function called "relative_positions" - this is a more general version of the atomic_neighbours function that returns all the atomic properties of atoms within a distance range of the given position.

You may find this useful to use in your function.