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 functionality to calculate minimum distance to cage atoms #24

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed pyef/.analysis.py.swp
Binary file not shown.
39 changes: 39 additions & 0 deletions pyef/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,43 @@ def calcdist(espatom_idx, charge_file):

return [distances_vertices, Ga_self_dist]

def calcNearestCageAtom(espatom_idx, charge_file):
df = pd.read_csv(charge_file, sep='\s+', names=["Atom",'x', 'y', 'z', "charge"])
k = 8.987551*(10**9) # Coulombic constant in kg*m**3/(s**4*A**2)

# Convert each column to list for quicker indexing
atoms = df['Atom']
charges = df['charge']
xs = df['x']
ys = df['y']
zs = df['z']

# Pick the index of the atom at which the esp should be calculated
idx_atom = espatom_idx

# Determine position and charge of the target atom
xo = xs[idx_atom]
yo = ys[idx_atom]
zo = zs[idx_atom]
chargeo = charges[idx_atom]
total_esp = 0

# Distance to cage atoms
cage_idxs = list(np.range(0, 280))
distances_toCage = []
counter = 0

for cage_idx in cage_idxs:
Cax = xs[cage_idx]
Cay = ys[cage_idx]
Caz = zs[cage_idx]
r = (((Cax - xo))**2 + ((Cay - yo))**2 + ((Caz - zo))**2)**(0.5)
distances_toCage.append(r)
array_dists = np.array(distances_toCage)
NearestCageAtom = np.min(array_dists)

return [NearestCageAtom]


def calcesp(espatom_idx, charge_range, charge_file):
"""
Expand Down Expand Up @@ -760,8 +797,10 @@ def getESPData(self, charge_types, ESPdata_filename):
# If .molden files deal with encapsulated TMCS, complete an additional set of analyses
if self.inGaCageBool:
[distoGa, Ga_selfdist]=Electrostatics.calcdist(atom_idx, full_file_path)
[cageAtomdist]=Electrostatics.calcNearestCageAtom(atom_idx, full_file_path)
results_dict['MetaltoGa_dist'] = distoGa
results_dict['GatoGa_dist'] = Ga_selfdist
results_dict['NearestCageAtom'] = cageAtomdist
else:
continue
except Exception as e:
Expand Down
Loading