Defines classes which represent bonds.
-
class
Bond(atom1, atom2, order, periodicity=(0, 0, 0), **kwargs)¶ Bases:
objectRepresents an atomic bond.
-
order¶ The bond order.
- Type
int
-
periodicity¶ The directions across which the bond is periodic. For example,
(1, 0, -1)means that when going fromatom1toatom2the bond is periodic across the x axis in the positive direction, is not periodic across the y axis and is periodic across the z axis in the negative direction.- Type
tupleofint
Examples
Adding additional attributes.
Each bond can be given additional attributes. For example
import stk bond1 = stk.Bond(stk.H(0), stk.H(1), 1) bond1.attr1 = 12.2 bond1.attr2 = 'something'
A
Bondcan also initialized with additional attributes directlybond2 = stk.Bond( atom1=stk.C(2), atom2=stk.C(3), order=1, attr1=123, attr2='hi' ) bond2.attr1 # Holds 123. bond2.attr2 # Holds 'hi'.
Printing
To print a brief summary of a bond you can run
# Prints Bond(C(2), C(3), 1). print(bond2)
To print a complete description of a bond, including additional attributes, you can run
# Prints Bond(C(2), C(3), 1, attr1=123, attr2='hi') print(repr(bond2))
If the atoms have additional attributes, they will be printed too
# Add a custom attribute to an atom. bond2.atom1.alpha = 1 # Prints Bond(C(2, alpha=1), C(3), 1, attr1=123, attr2='hi') print(repr(bond2))
If private attributes were added to a bond, they will not be printed
bond2._attr3 = 'private' # Prints Bond(C(2, alpha=1), C(3), 1, attr1=123, attr2='hi') print(repr(bond2))
Methods
clone(self[, atom_map])Return a clone.
is_periodic(self)Return
Trueif the bond is periodic.-
__init__(self, atom1, atom2, order, periodicity=(0, 0, 0), **kwargs)¶ Initialize a
Bond.-
atom1 The first atom in the bond.
- Type
-
atom2 The second atom in the bond.
- Type
-
order The bond order.
- Type
int
-
periodicity The directions across which the bond is periodic. For example,
(1, 0, -1)means that when going fromatom1toatom2the bond is periodic across the x axis in the positive direction, is not periodic across the y axis and is periodic across the z axis in the negative direction.- Type
tupleofint, optional
-
**kwargs Additional attributes to be added to the bond.
- Type
object, optional
-
-
clone(self, atom_map=None)¶ Return a clone.
Private attributes are not passed to the clone.
- Parameters
atom_map (
dict, optional) – If the clone should hold differentAtominstances, then adictshould be provided, which maps atoms in the currentBondto the atoms which should be used in the clone. Only atoms which need to be remapped need to be present in the atom_map.- Returns
The clone.
- Return type
Examples
import stk c0 = stk.C(0) c1 = stk.C(1) bond = stk.Bond(c0, c1, 1, custom_attr=12, _private_attr=1) # bond_clone holds c0 and c1 in its atom1 and atom2 # attributes, respectively. It also has a custom_attr # with a value of 12 but it does not have a _private_attr # attribute. bond_clone = bond.clone()
It is possible to make sure that the clone holds different atoms
li2 = stk.Li(2) n3 = stk.N(3) # clone2 is also a clone, except that it holds # li2 in the atom2 attribute. Its atom1 attribute still # holds c0. clone2 = bond.clone(atom_map={ c1: li2 }) # clone3 is also a clone, except that it holds n3 and # li2 in its atom1 and atom2 attributes, respectively. clone3 = bond.clone(atom_map={ c0: n3, c1: li2 })
-
is_periodic(self)¶ Return
Trueif the bond is periodic.- Returns
Trueif the bond is periodic.- Return type
bool
-