Skip to content

Commit d3b3599

Browse files
committed
added multiplier for natural cutoffs, increasing modularity of get_connectivity and evaluate_binding functions
1 parent 9628a3b commit d3b3599

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

autoadsorbate/utils.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,31 @@ def __init__(self):
2222
self.message = 'Molecule is in gas phase'
2323
super().__init__(self.message)
2424

25-
def get_connectivity(atoms: ase.Atoms) -> np.ndarray:
25+
def get_connectivity(atoms: ase.Atoms, mult:float = 1.0) -> np.ndarray:
2626
"""Get the connectivity matrix of an ASE Atoms object.
2727
Parameters:
2828
atoms (ase.Atoms): The ASE Atoms object.
29+
mult (float): Multiplier for the natural cutoffs.
2930
Returns:
3031
np.ndarray: The connectivity matrix.
3132
"""
32-
cutoffs = natural_cutoffs(atoms)
33+
cutoffs = natural_cutoffs(atoms, mult=mult)
3334
nl = NeighborList(cutoffs, self_interaction=False, bothways=True)
3435
nl.update(atoms)
3536

3637
return nl.get_connectivity_matrix(sparse=False)
3738

38-
def evaluate_binding(atoms, mol_indices=None):
39+
def evaluate_binding(atoms:ase.Atoms, mol_indices:None|list[int] = None, mult:float=1.0) -> dict:
40+
"""Evaluate the binding of a molecule to a surface by analyzing the connectivity and distances.
41+
Parameters:
42+
atoms (ase.Atoms): The ASE Atoms object.
43+
mol_indices (list): Optional list of indices corresponding to the molecule. If None, it will be determined from the atoms object.
44+
mult (float): Multiplier for the natural cutoffs when determining connectivity.
45+
Returns:
46+
dict: A dictionary containing the binding sites and molecule indices.
47+
Raises:
48+
MoleculeDesorptionError: If the molecule is found to be desorbed (i.e., no binding sites detected).
49+
"""
3950
if mol_indices is not None:
4051
mol_inds = mol_indices
4152

@@ -56,12 +67,12 @@ def evaluate_binding(atoms, mol_indices=None):
5667
mol_inds = np.array(mol_inds) + len(atoms)*2
5768
atoms = atoms*(2,2,1)
5869

59-
C = get_connectivity(atoms)
70+
C = get_connectivity(atoms, mult=mult)
6071
adsorption_idx = []
6172
for i in mol_inds:
6273
for j, connected in enumerate(C[i]):
63-
if connected and j not in mol_inds and j not in adsorption_idx :
64-
adsorption_idx .append(j)
74+
if connected and j not in mol_inds and j not in adsorption_idx:
75+
adsorption_idx.append(j)
6576

6677
bondlengths = []
6778
for i in adsorption_idx :

0 commit comments

Comments
 (0)