All About Potentials and Iterators David A Kofke
All About Potentials and Iterators David A. Kofke Department of Chemical Engineering University at Buffalo, State University of New York
Potential • Top-level simulation element – Species, Potential, Integrator, Controller, Meter, Device, Display • Defines methods and holds fields that define interactions between atoms • Potential is responsible for knowing the atoms to which it applies – Uses appropriate iterators for this purpose • Hierarchical structure that parallels structure of species hierarchy 2
Atom • Corresponds to a physical atom (in simplest case) • Holds data relating to – – Spatial coordinate (position and/or momentum) Atom type Position in atom hierarchy Position in atom sequence • Can also hold auxiliary data – Agents from other classes – Parameters specified by other classes (in type field) – Lists of other atoms for use by other classes 3
Atom Fields parent. Group (via node) Space makes Atom. Factory makes type coord seq node makes allatom. Agents[] any classes ia makes Integrator child. List (via node) 4 next (via seq) Atom previous (via seq)
Species Hierarchy Species 1 Species 2 Phase makes Molecule layer Leaf atoms 5 makes
Species Hierarchy Species 1 Species 2 Phase Depth 0 1 Molecule layer 2 3 first. Leaf. Atom of Species. Master, Species. Agent 1 last. Leaf. Atom of Species. Agent 1 first. Leaf. Atom of Species. Agent 2, Atom. Group 1 6 last. Leaf. Atom of Species. Master, Species. Agent 2, Atom. Group N
Ordering • Atoms are ordered to facilitate looping through them Species. Master (000) Species. Agent 1 (100) Atom 1 (110) Atom 2 (120). . . Species. Agent 2 (200) Atom. N (1 N 0) Atom. Group 1 (210). . . Atom 1 (211). . . Atom n (21 n) . . . Atom. Group. N (2 N 0) Atom 1 (2 N 1). . . Atom n (2 Nn) • 000 110 120 … 1 N 0 200 211 … 21 n … 2 N 0 2 N 1 2 Nn • Looping might be required to go up or down list, from any point, and at any level in hierarchy • Ordering might be fixed, or might depend on spatial configuration (cell neighbor list) 7
Potential Hierarchy • Potential hierarchy parallels species hierarchy – Higher-level potentials define interactions between larger groups of atoms Potential. Master Potential 2 A Potential. Group B Potential 2 Ba Potential. Group D Potential. Group C Potential 2 Ca Potential 2 Cb Potential 2 Da Species. Master Species. Agent 1 Atom 2. . . Species. Agent 2 Atom. N Atom. Group 1. . . Atom 1. . . 8 . . . Atom n . . . Atom. Group. N Atom 1. . . Atom n
Potential Hierarchy • Potential hierarchy parallels species hierarchy – Higher-level potentials define interactions between larger groups of atoms Potential. Master Potential 2 A iterates over pairs Potential. Group B Potential. Group C formed from children of Species. Agent 1 Potential 2 Ca Potential 2 Ba Potential 2 Cb Potential. Group D Potential 2 Da Species. Master Species. Agent 1 Atom 2. . . Species. Agent 2 Atom. N Atom. Group 1. . . Atom 1. . . 9 . . . Atom n . . . Atom. Group. N Atom 1. . . Atom n
Potential Hierarchy • Potential hierarchy parallels species hierarchy – Higher-level potentials define interactions between larger groups of atoms Potential. Group B iterates over pairs formed from children of Potential. Group D Potential. Group C Species. Agent 1 and Species. Agent 2 Potential. Master Potential 2 A Potential. Group B Potential 2 Ba Potential 2 Ca Potential 2 Cb Potential 2 Da Species. Master Species. Agent 1 Atom 2. . . Species. Agent 2 Atom. N Atom. Group 1. . . Atom 1. . . 10 . . . Atom n . . . Atom. Group. N Atom 1. . . Atom n
Potential Hierarchy • Potential hierarchy parallels species hierarchy – Higher-level potentials define interactions between larger groups of atoms Potential 2 Ba iterates over pairs formed from species 1 molecule and Potential. Group D C atoms Potential. Group of a species 2 molecule Potential. Master Potential 2 A Potential. Group B Potential 2 Ba Potential 2 Ca Potential 2 Cb Potential 2 Da Species. Master Species. Agent 1 Atom 2. . . Species. Agent 2 Atom. N Atom. Group 1. . . Atom 1. . . 11 . . . Atom n . . . Atom. Group. N Atom 1. . . Atom n
Potential Hierarchy • Potential hierarchy parallels species hierarchy – Higher-level potentialsover define interactions between larger groups of atoms Potential. Group C iterates single molecules that are children of Potential. Master Species. Agent 2 Potential 2 A Potential. Group B Potential 2 Ba Potential. Group D Potential. Group C Potential 2 Ca Potential 2 Cb Potential 2 Da Species. Master Species. Agent 1 Atom 2. . . Species. Agent 2 Atom. N Atom. Group 1. . . Atom 1. . . 12 . . . Atom n . . . Atom. Group. N Atom 1. . . Atom n
Potential Hierarchy • Potential hierarchy parallels species hierarchy Higher-level potentials define interactions between larger groups of atoms For a–given species-2 molecule, Potential. Group Ca and Cb iterate Potential. Master over pairs formed from its children Potential 2 A Potential. Group B Potential 2 Ba Potential. Group D Potential. Group C Potential 2 Ca Potential 2 Cb Potential 2 Da Species. Master Species. Agent 1 Atom 2. . . Species. Agent 2 Atom. N Atom. Group 1. . . Atom 1. . . 13 . . . Atom n . . . Atom. Group. N Atom 1. . . Atom n
Potential Hierarchy • Potential hierarchy parallels species hierarchy – Higher-level potentials define interactions between larger groups of atoms Potential. Master Potential 2 A Potential. Group B Potential. Group D Potential. Group C Potential. Group D iterates over pairs Ba Potential 2 Ca Potential 2 Cb formed. Potential 2 from children of Species. Agent 2 Potential 2 Da Species. Master Species. Agent 1 Atom 2. . . Species. Agent 2 Atom. N Atom. Group 1. . . Atom 1. . . 14 . . . Atom n . . . Atom. Group. N Atom 1. . . Atom n
Potential Hierarchy • Potential hierarchy parallels species hierarchy – Higher-level potentials define interactions between larger groups of atoms Potential. Master Potential 2 A Potential. Group B Potential. Group D Potential. Group C For a given pair of species 2 molecules, Potential 2 Ba Ca Potential 2 Cb Potential. Group Da Potential 2 iterates over pairs formed from their children Potential 2 Da Species. Master Species. Agent 1 Atom 2. . . Species. Agent 2 Atom. N Atom. Group 1. . . Atom 1. . . 15 . . . Atom n . . . Atom. Group. N Atom 1. . . Atom n
Using the Potentials • To get information from potential, we need to tell it – What calculation is to be done • Energy, virial, force, collision time, etc. Potential. Master – What atom group is the basis for its calculation Potential 2 B • ADefines. Potential. Group set of atoms Potential. Group D Potential. Group C subject to iteration • e. g. Potential 2 Da iterates over different atoms depending on what pair of molecules Potential. Group D Ca is on Potential 2 Cb Potential 2 Da Potential 2 Ba – Which atoms are the focus of the calculation • All pairs it applies to, or… • …only pairs involving a given atom Species. Master – Then, only 1 atoms up, down, or both directions from it? 2 Species. Agent Atom 1 Atom 2. . . Atom. N Atom. Group 1. . . Atom 1. . . 16 . . . Atom n . . . Atom. Group. N Atom 1. . . Atom n
Using the Potentials • Basic format (current) Current form potential. set(basis). calculate(iterator. Directive, energy. Calculation); New form potential. calculate(basis, iterator. Directive, energy. Calculation); • Arguments – basis: Defines set of atoms subject to iteration – iterator. Directive: specifies type of iteration desired – energy. Calculation: contains method to perform desired calculation • Process (examine code, but currently under revision) 17 – calculate method sets up potential’s iterator for looping, and instructions in energy. Calculation are performed
Iterator Directive • Iterator. Directive holds fields that direct iteration – Key attributes (among a few others) • direction – UP, DOWN, BOTH, NEITHER • atom – iteration performed in reference to atom, if not null • Basis defines the source of atoms for the iterator – Within a given basis, iterator may loop over atoms in different ways • Depends on iterator. Directive • Depends on design of iterator 18 – – – All children Children two (e. g. ) steps deeper “neighbors” only Only ones bonded/not bonded to an atom Only first or last child Etc.
Using an Iterator • Perform actions on iterates (pass atoms to action) iterator. reset(); while(iterator. has. Next()) { Atom atom = iterator. next(); //do something with atom } • Pass action to iterator Atom. Action action =. . . //define action iterator. all(basis, directive, action); //performs action on directed atoms //in basis 19
Threading in Java • Independent process of calculation – In single-processor platforms, control moves from one thread to another in unpredictable ways – In multi-processor platforms, each processor can be running a different thread • Different threads may be using the same data, or the same instances of objects – Must be careful that threads do not interfere or corrupt each other’s activities • Possible paradigm for conducting parallelized simulations – Different parallel-tempering phases running on individual threads – Simulations on a single phase might use different threads to advance simulation in different regions of space 20
Problem with Multithreading • Only one potential hierarchy is instantiated • Threads running in different phases operate on hierarchy simultaneously – E. g. Thread 1 has Potential 2 A iterating over atoms in its phase – In the middle of this, Thread 2 comes in and resets iteration for atoms in another phase Potential. Master Potential 2 A Potential. Group B Potential 2 Ba 21 Potential. Group C Potential 2 Ca Potential 2 Cb Potential. Group D Potential 2 Da
Solutions to Multithreading Problem • Construct identical potential hierarchies, each devoted to a single thread – Complicated by need to ensure that potentials always remain identically defined across all instances – Modifications (change in parameters or addition/removal of a potential) must be transmitted to all instances – Difficulty can be alleviated by defining hierarchy of potential agents • Agents have individual iterators • Agents refer to single, common hierarchy of potentials for their definition • Use stateless iteration (demonstration) – – 22 Pass calculation to iterator Much easier, less error-prone to program, understand, and maintain Performance issues? Current modifications are now following this path
- Slides: 22