This problem was long proposed in BIOCAD, and they expected it to be programmed for CUDA / OpenCL - however after testing it a bit I think it is good enough for any language.
The task is to calculate intra-molecular energy - simply as a sum of energy (electrostatic) between every pair of atoms in it, regarding atoms as
a dimensionless charges. E.g. energy attracting two atoms, A
and B
is calculated like this:
Q(A) * Q(B)
E(A, B) = C * -------------
R(A, B)
Here Q(x)
is the charge of the atom and R(m, n)
is the distance between two atoms. You will be given charges and coordinates.
Constant factor is C = 1389.38757
.
However amendment to the calculated energy value should be made due to bonds between atoms:
3
bonds linking the two atoms, their energy should be halved;Input: The first line gives Na
- number of atoms in molecule.
Then Na
lines follow, each with four values Xi Yi Zi Qi
- coordinates and charge of i-th
atom.
Next here comes line with single value Nb
- number of bonds.
It is followed by Nb
lines, each containing a pair of integers - indices of atoms which have a bond between them. Bonds are bi-directional,
atom indices are zero-based.
Answer: resultant energy, rounded to nearest integer.