Molecular representations and optimization variables
This is the first post in a series on the mathematical foundations of molecular modeling. The starting point is to distinguish the chemical object being modeled, its spatial arrangement, and the parameters of a predictive model.
We then introduce molecular graphs and feature matrices, explain the roles of several matrix operations, and connect these representations to optimization and sampling. One small example, ethanol and dimethyl ether, illustrates why element identities and connectivity must be used together.
1. Chemical identity, coordinates, and model parameters
The phrase molecular optimization is ambiguous until we specify what changes during the calculation. Three objects will appear throughout this post.
| Symbol | Meaning | What a change can represent |
|---|---|---|
| Chemical specification of a molecule | A different chemical candidate | |
| Atomic coordinate matrix | A different spatial arrangement | |
| Trainable parameters of a predictive model | A different prediction for the same input |
The chemical specification includes element identities, connectivity, bond types, formal charges, and relevant hydrogen and stereochemical information. A molecular formula alone is generally insufficient to specify a molecule.
Two chemical terms help separate these ideas:
- Constitution describes atom identities, connectivity, and bond multiplicities.
- Conformation describes spatial arrangements that can primarily be interconverted through rotations around single bonds.
These definitions follow the IUPAC Gold Book entries for constitution and conformation.
One chemical specification can admit many coordinate arrangements. In particular, a rigid translation or rotation changes coordinates without changing the internal conformation. A change in constitution changes ; coordinates for the new chemical input must be specified separately.
The notation , , and is used here to separate quantities that can participate in different stages of one computational workflow.
2. Molecular graphs and features
2.1 Graph representation
A graph is a pair
where is the set of nodes and is the set of edges. In a molecular graph, nodes represent atoms and edges represent bonds.
An unlabeled connectivity graph alone does not contain all the information required to identify a molecule. Atom and bond attributes must also be recorded. The graph and feature-matrix definitions used here follow Hamilton, Graph Representation Learning, Sections 1.1 and 1.1.2.
An atom’s index identifies it in a chosen ordering. This is distinct from its atomic number , which identifies its element.
2.2 Adjacency matrix
For a simple undirected graph with represented atoms, define the adjacency matrix by
With no self-loops, . Because the graph is undirected,
The number of represented neighbors of atom is its degree:
Each undirected edge contributes twice to the sum of all matrix entries, so
Degree and bond order describe different things. Degree counts neighboring nodes, whereas bond order describes a bond’s multiplicity. A binary adjacency matrix records a double bond as one connection, not two. Omitted hydrogen nodes do not contribute to degree.
2.3 Atom and bond features
An atom-feature matrix
contains features per atom. Row of must describe the atom associated with row and column of .
Features may encode element identity, formal charge, aromaticity, or other relevant information. Bond features can be stored separately, with each feature vector explicitly associated with its corresponding atom pair.
Consistent reindexing changes the arrays but not the molecule they represent. Reordering alone while leaving unchanged can misassign chemical features.
2.4 Hydrogens and representation size
counts the atoms explicitly represented, not necessarily all atoms in the chemical formula. Ethanol has three non-hydrogen atoms and nine atoms including hydrogens. The RDKit documentation illustrates implicit and explicit hydrogen handling.
Adding hydrogen nodes changes the atom-related dimensions of , , and . The feature definition must also specify how hydrogen is represented.
3. What the matrix operations mean
3.1 Feature transformation:
Let
Then
Writing and as row vectors,
The same transformation is applied independently to each atom. The number of atoms remains , while the number of features changes from to .
may be part of the trainable parameters . The output columns of are transformed features; they need not retain the original interpretation of the columns of .
Importantly, alone does not use connectivity. Identical input rows produce identical output rows under the same .
3.2 Neighborhood aggregation:
The product
has rows
where denotes the neighbors of atom .
Thus, sums the features of neighboring atoms. With , it does not include the central atom itself.
This is an elementary form of neighborhood aggregation, an operation used within graph neural networks. The corresponding concepts are developed in Hamilton, Section 5.1.3. Here, has no trainable parameters and is not a complete GNN model.
3.3 Molecular aggregation: summing atom vectors
One way to obtain a vector for an entire molecule is
This sums across atoms, combining their row vectors component by component. It does not sum the entries within each row to produce one scalar per atom.
This operation is a simple form of graph pooling, discussed in Hamilton, Section 5.5.
3.4 Example: ethanol and dimethyl ether
For this illustrative example, omit hydrogen nodes and order the atoms along each chain:
Both have the same unlabeled connectivity matrix under these orderings:
Using the feature columns [carbon indicator, oxygen indicator],
Their atom-labeled molecular graphs differ even though is the same.
If we only transform each atom by a shared and sum, then
For both molecules,
This representation therefore cannot distinguish them for any shared : it uses element counts but ignores connectivity.
Incorporating adjacency gives
The oxygen row is row 3 in ethanol and row 2 in dimethyl ether. Its neighboring-carbon count is respectively 1 and 2.
Reading together with therefore exposes a difference in oxygen’s local environment. This does not imply that alone uniquely identifies every molecule.
4. Coordinates, conformations, and poses
Let be the position of atom , written as a column vector. The coordinate matrix is
The distance between two atoms is
Under a common rigid transformation,
where is a proper rotation matrix and is a translation vector.
For any pair of atoms,
Rigid translation and rotation preserve internal geometry even though changes.
A ligand’s pose describes its placement and configuration relative to a receptor. If the receptor is fixed while only the ligand moves, ligand–receptor distances can change despite unchanged distances within the ligand.
Docking therefore searches over position, orientation, and relevant internal torsions. The AutoDock Vina paper provides a concrete example of this distinction between search variables and the scoring function.
5. Three optimization problems
The operator returns an objective value; identifies the arguments attaining it. Writing an optimization problem specifies the target, not a guarantee that a numerical algorithm finds its global solution.
5.1 Coordinate optimization
For a fixed chemical specification and energy model , write
where denotes the allowed coordinates under the chosen chemical specification and constraints.
Alternatively, use internal or pose variables and construct coordinates through
Gradient descent is not restricted to convex objectives. Gradient-based methods can be applied to suitable nonconvex objectives, but global optimality is not automatically guaranteed. This distinction is discussed in Deep Learning, Section 4.3.
Molecular energy landscapes are generally nonconvex. For a constrained problem to be convex, convexity of both the objective and the feasible set is relevant. Convergence guarantees also depend on regularity, step-size choices, and the algorithm used.
5.2 Predictive-model training and inference
Given labeled examples , a simple training objective is
where
Here, counts data pairs, whereas counts represented atoms in one molecule. The notation is shorthand for a model operating on a numerical representation of ; a three-dimensional model may also take as input.
Training changes using data and an objective. Inference evaluates a new input with trained parameters held fixed:
Supplying a new molecule to a trained model does not, by itself, constitute training. A prediction is also distinct from a new experimental measurement. The underlying model-and-loss viewpoint is developed in Deep Learning, Chapter 6.
5.3 Molecular design and search
Let be the set of allowed chemical candidates. If larger scores are better, molecular search seeks
A learned evaluator can be used as
with fixed during this search stage.
A score may also be computed without a learned model. MolFinder illustrates evolutionary molecular search whose basic method does not require training a generative neural network.
Direct changes to atom identities and connectivity involve discrete choices. Ordinary gradients with respect to Cartesian coordinates do not directly define updates to those choices. Differentiable alternative representations or other search methods require an explicit formulation.
6. Optimization versus sampling
Optimization seeks solutions that improve an objective. Sampling seeks states distributed according to a target probability distribution .
For a discrete state space ,
Selecting a most probable state,
is different from generating samples from the full distribution. Finite-sample frequencies need not equal the target probabilities exactly.
An optimization algorithm may use random proposals. Randomness alone does not establish that it samples an equilibrium distribution correctly. The connection between molecular energies and equilibrium probabilities requires additional statistical-mechanical concepts, beyond the scope of this introductory post.
7. Summary
| Task | Main variable | Intended result |
|---|---|---|
| Coordinate optimization | or internal/pose variables | Favorable geometry or pose |
| Model training | Improved predictive performance under a training objective | |
| Molecular search | A candidate with a favorable objective value | |
| Sampling | Generated or visited states | Samples consistent with a target distribution |
One possible ML-guided design workflow is to train a predictor, hold its parameters fixed, and use its predictions to guide molecular search. This is one workflow rather than a prerequisite for all molecular modeling.
The matrix operations can also be summarized by their roles:
| Representation or operation | Role |
|---|---|
| Input features of individual atoms | |
| Shared transformation of each atom’s features | |
| Summation of neighboring atoms’ features | |
| Aggregation into a molecular vector |
To understand a molecular modeling algorithm, identify the representation, the variables that change, the quantities held fixed, and the objective or target distribution.
8. References
- William L. Hamilton. Graph Representation Learning. 2020. Sections 1.1, 1.1.2, 5.1.3, and 5.5. Author’s PDF.
- Ian Goodfellow, Yoshua Bengio, and Aaron Courville. Deep Learning. MIT Press, 2016. Chapters 2, 4, and 6. Official online textbook.
- IUPAC Gold Book. Constitution and Conformation.
- RDKit documentation. Getting Started with the RDKit in Python. Sections “Looping over Atoms and Bonds” and “Modifying molecules.” Official documentation.
- Oleg Trott and Arthur J. Olson. “AutoDock Vina: improving the speed and accuracy of docking with a new scoring function, efficient optimization and multithreading.” Journal of Computational Chemistry, 31:455–461, 2010. DOI: 10.1002/jcc.21334.
- Y. Kwon and J. Lee. “MolFinder: an evolutionary algorithm for the global optimization of molecular properties and the extensive exploration of chemical space using SMILES.” Journal of Cheminformatics, 13:24, 2021. DOI: 10.1186/s13321-021-00501-7.