Skip to content

Commit 840d75b

Browse files
committed
enh: let user determine which distance to be considered an existing bond
1 parent bda662d commit 840d75b

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

sisl/geometry.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3066,7 +3066,7 @@ def bond_correct(self, ia, atom, method='calc'):
30663066
raise NotImplementedError(
30673067
'Changing bond-length dependent on several lacks implementation.')
30683068

3069-
def bond_completion(self, nbonds, atom=None, bond=None, idx=None):
3069+
def bond_completion(self, nbonds, bond=None, new_bond=None, atom=None, idx=None):
30703070
""" Return a new geometry with additional atoms added to complete the number of bonds
30713071
30723072
This function may be useful to saturate dangling bonds at edges in sp2-carbon structures,
@@ -3076,10 +3076,12 @@ def bond_completion(self, nbonds, atom=None, bond=None, idx=None):
30763076
----------
30773077
nbonds : int
30783078
number of bonds requested
3079-
atom : `Atom`, optional
3080-
the kind of atom to be added, where missing. Defaults to atoms of the same type.
30813079
bond, float, optional
3082-
bond length to the extra atoms. Defaults to value from `PeriodicTable`
3080+
distance between existing atoms to be considered a bond. Defaults to value from `PeriodicTable`
3081+
new_bond, float, optional
3082+
bond length to added atom. Defaults to value from `PeriodicTable`
3083+
atom : `Atom`, optional
3084+
kind of atom to be added, where missing. Defaults to atoms of the same type.
30833085
idx : array_like, optional
30843086
List of indices for atoms that are to be considered
30853087
@@ -3102,9 +3104,13 @@ def bond_completion(self, nbonds, atom=None, bond=None, idx=None):
31023104
PT = PeriodicTable()
31033105

31043106
for ia in selection:
3105-
iaZ = self.atoms[ia].Z
3106-
ria = PT.radius(iaZ)
3107-
idx = self.close(ia, R=(0.1, 0.1 + 2 * ria), ret_xyz=True)
3107+
a = self.atoms[ia]
3108+
# Determine radius of sphere for bond search
3109+
if bond is None:
3110+
ria = 0.1 + 2 * PT.radius(a.Z)
3111+
else:
3112+
ria = 1e-4 + bond
3113+
idx = self.close(ia, R=(0.1, ria), ret_xyz=True)
31083114
# We just need second shell coordinates
31093115
xyz = idx[1][1]
31103116
if len(xyz) == nbonds - 1:
@@ -3114,16 +3120,16 @@ def bond_completion(self, nbonds, atom=None, bond=None, idx=None):
31143120
if bnorm > 0.1:
31153121
# only add to geometry if new position is away from ia-atom
31163122
if atom is None:
3117-
this_atom = Atom(iaZ, R=self.atoms[ia].R)
3123+
new_a = Atom(a.Z, R=a.R)
31183124
else:
3119-
this_atom = atom
3120-
if bond is None:
3121-
bond_length = ria + PT.radius(this_atom.Z)
3125+
new_a = atom
3126+
if new_bond is None:
3127+
bond_length = PT.radius(a.Z) + PT.radius(new_a.Z)
31223128
else:
3123-
bond_length = bond
3129+
bond_length = new_bond
31243130
bvec *= bond_length / bnorm
31253131
new_xyz.append(self.xyz[ia] + bvec)
3126-
new_atom.append(this_atom)
3132+
new_atom.append(new_a)
31273133
if len(new_xyz) > 0:
31283134
return self.add(self.__class__(new_xyz, new_atom))
31293135
else:

0 commit comments

Comments
 (0)