Skip to content

Exercise 4

Part of the course Computational Chemistry.

Classical potentials are commonly used for extended systems where the collective behavior is more important to the modelling effort than the exact energy of individual configurations. Here, we prepare a simple implementation of one term of a classical potential.

Task 4.1: Book keeping

Write a class Atom to hold all properties of an atom, i.e. nuclear charge and position. Then write another class Bond which connects any two instances of Atom. The class Bond should have a method length() which returns the distance of the bonded atoms.

Example:

atom1 = Atom(Z=6, x=0, y=0, z=0)
atom2 = Atom(Z=8, x=1, y=0, z=0)
bond = Bond(atom1, atom2)
bond.length() == 1

Optional: Use dataclasses instead. What is their main advantage? Implement the bond length to be a property rather than a class method.

Task 4.2: Connecting the dots

Write a class Molecule which takes an iterable of bonds and has the method number_of_atoms() to return the total number of atoms in that molecule.

Optional: Check whether the molecule is indeed a molecule by checking whether it is fully connected.

Task 4.3: So much potential

Write a new class ClassicalPotential which mimics a simple force field. For each bond type (i.e. elements involved), assume a harmonic potential with some equilibrium bond length and force constants. You may assume some arbitrary values here. Design the class such that you can write the following:

mol = Molecule(list_of_bonds)
pot = ClassicalPotential()
pot.set_parameters(element1, element2, equilibrium_distance, force_constant)
...
pot.evaluate(mol)