Skip to content

Commit f1d9691

Browse files
committed
enh: let user determine which distance to be considered an existing bond
1 parent 330f2b6 commit f1d9691

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
@@ -2599,7 +2599,7 @@ def bond_correct(self, ia, atom, method='calc'):
25992599
raise NotImplementedError(
26002600
'Changing bond-length dependent on several lacks implementation.')
26012601

2602-
def bond_completion(self, nbonds, atom=None, bond=None, idx=None):
2602+
def bond_completion(self, nbonds, bond=None, new_bond=None, atom=None, idx=None):
26032603
""" Return a new geometry with additional atoms added to complete the number of bonds
26042604
26052605
This function may be useful to saturate dangling bonds at edges in sp2-carbon structures,
@@ -2609,10 +2609,12 @@ def bond_completion(self, nbonds, atom=None, bond=None, idx=None):
26092609
----------
26102610
nbonds : int
26112611
number of bonds requested
2612-
atom : `Atom`, optional
2613-
the kind of atom to be added, where missing. Defaults to atoms of the same type.
26142612
bond, float, optional
2615-
bond length to the extra atoms. Defaults to value from `PeriodicTable`
2613+
distance between existing atoms to be considered a bond. Defaults to value from `PeriodicTable`
2614+
new_bond, float, optional
2615+
bond length to added atom. Defaults to value from `PeriodicTable`
2616+
atom : `Atom`, optional
2617+
kind of atom to be added, where missing. Defaults to atoms of the same type.
26162618
idx : array_like, optional
26172619
List of indices for atoms that are to be considered
26182620
@@ -2635,9 +2637,13 @@ def bond_completion(self, nbonds, atom=None, bond=None, idx=None):
26352637
PT = PeriodicTable()
26362638

26372639
for ia in selection:
2638-
iaZ = self.atoms[ia].Z
2639-
ria = PT.radius(iaZ)
2640-
idx = self.close(ia, R=(0.1, 0.1 + 2 * ria), ret_xyz=True)
2640+
a = self.atoms[ia]
2641+
# Determine radius of sphere for bond search
2642+
if bond is None:
2643+
ria = 0.1 + 2 * PT.radius(a.Z)
2644+
else:
2645+
ria = 1e-4 + bond
2646+
idx = self.close(ia, R=(0.1, ria), ret_xyz=True)
26412647
# We just need second shell coordinates
26422648
xyz = idx[1][1]
26432649
if len(xyz) == nbonds - 1:
@@ -2647,16 +2653,16 @@ def bond_completion(self, nbonds, atom=None, bond=None, idx=None):
26472653
if bnorm > 0.1:
26482654
# only add to geometry if new position is away from ia-atom
26492655
if atom is None:
2650-
this_atom = Atom(iaZ, R=self.atoms[ia].R)
2656+
new_a = Atom(a.Z, R=a.R)
26512657
else:
2652-
this_atom = atom
2653-
if bond is None:
2654-
bond_length = ria + PT.radius(this_atom.Z)
2658+
new_a = atom
2659+
if new_bond is None:
2660+
bond_length = PT.radius(a.Z) + PT.radius(new_a.Z)
26552661
else:
2656-
bond_length = bond
2662+
bond_length = new_bond
26572663
bvec *= bond_length / bnorm
26582664
new_xyz.append(self.xyz[ia] + bvec)
2659-
new_atom.append(this_atom)
2665+
new_atom.append(new_a)
26602666
if len(new_xyz) > 0:
26612667
return self.add(self.__class__(new_xyz, new_atom))
26622668
else:

0 commit comments

Comments
 (0)