Cluster Search¶
Install the package, then run a 38-point Lennard-Jones search with the measured configuration.
pip install anneal
import numpy as np
from anneal import Config, cluster_search
def lj(x):
p = x.reshape(-1, 3)
d = p[:, None] - p
r2 = (d * d).sum(-1)
iu = np.triu_indices(len(p), 1)
inv6 = (1.0 / r2[iu]) ** 3
return float(4.0 * np.sum(inv6 * inv6 - inv6))
def lj_g(x):
p = x.reshape(-1, 3)
d = p[:, None] - p
r2 = (d * d).sum(-1)
np.fill_diagonal(r2, np.inf)
inv2 = 1.0 / r2
inv6 = inv2 ** 3
c = 24.0 * inv2 * (2.0 * inv6 * inv6 - inv6)
return np.einsum("ij,ijk->ik", c, d).ravel()
cfg = Config.recommended(38)
out = cluster_search(lj, lj_g, cfg.n_points, 4000, seed=0, recommended=True)
print(out["hops"], round(out["best_energy"], 3), len(out["best"]))
Expected output (seed 0)::
PLACEHOLDER
Direct quantum-chemistry profiles¶
The molecular-cluster and slab examples use the same persistent
ProfileEngine. The adapter loads a conforming potential library once, turns
each energy-and-force result into the optimizer’s value-and-gradient pair, and
owns the session for the full hop loop. Selecting nwchemc calls
libnwchemc in process; no RPC server or result cache participates. Molecular
requests omit a simulation cell and slab requests carry their periodic cell
through the same request type.
POTENTIAL_CONFIG=/path/to/PotentialConfig.bin \
POTENTIAL_LIBRARY=/path/to/libnwchemc.so \
cargo run --locked --release --features rgpot-ex \
--example molecular_cluster -- 6 1200 8 nwchemc
The shared adapter is examples/common/profile_engine.rs. The molecular and
periodic consumers are examples/molecular_cluster.rs and
examples/slab_adsorption.rs.