molclusters.tracker¶
tracker
¶
Provides the ClusterTracker class, which follows molecular clusters over a trajectory.
The tracker only keeps the clusters and their ids up to date, frame by frame; the
analyses built on them (and all file output) live in molclusters.molclusters.
Classes:
- ClusterTracker: Finds the clusters of the current frame and keeps their ids stable across formation, growth, split, merge and dissolution events.
- Transition: How the clusters of a frame came from those of the frame before.
Transition
dataclass
¶
Transition(flows: Mapping[tuple[int, int], int], born: frozenset[int] = frozenset(), merged: Mapping[int, int] = MappingProxyType({}), dissolved: frozenset[int] = frozenset())
How the clusters of a frame came from those of the frame before.
Merges and splits may involve any number of clusters. A merge ends every
cluster that merged maps to the same survivor. A split shows as the new
clusters whose sources include a previous cluster, however many: a cluster
breaking into several pieces has a new cluster per piece but the one it
continues in, and a new cluster made of pieces of several clusters has each
of them as a source.
For the first frame, every cluster is born, of free molecules.
Attributes:
| Name | Type | Description |
|---|---|---|
flows |
Mapping[tuple[int, int], int]
|
(previous cluster id, current cluster id) -> how many molecules went from
the one to the other, id |
born |
frozenset[int]
|
The clusters new in this frame. |
merged |
Mapping[int, int]
|
Each previous cluster that ended in a merge -> the cluster that absorbed it
(both chose the same group, and the other continues in it; see
|
dissolved |
frozenset[int]
|
The previous clusters that ended without merging: no group held two or more of their molecules. |
ended
property
¶
sources
¶
Tell where the molecules of a current cluster came from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cluster_id
|
int
|
A cluster of the current frame. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, int]
|
Previous cluster id ( |
Source code in src/molclusters/tracker.py
destinations
¶
Tell where the molecules of a previous cluster went.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cluster_id
|
int
|
A cluster of the previous frame. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, int]
|
Current cluster id ( |
Source code in src/molclusters/tracker.py
absorbed
¶
Tell which previous clusters merged into a current one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cluster_id
|
int
|
A cluster of the current frame. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
The ids of the clusters it absorbed, in increasing order (empty if none). |
Source code in src/molclusters/tracker.py
ClusterTracker
¶
ClusterTracker(universe: Universe, config: MolClsConfig)
Follows the molecular clusters of a trajectory, keeping their ids stable.
The clusters of the frame the Universe is on are found on creation; after
moving the trajectory to another frame, update reconciles them with it.
Attributes:
| Name | Type | Description |
|---|---|---|
uni |
Universe
|
The MDAnalysis Universe object associated with the simulation. |
config |
MolClsConfig
|
The analysis configuration (only its rules, distance backend and ignored compositions are used). |
sels |
dict[str, AtomGroup]
|
Atom groups for each residue type. |
conntab |
ConnectionTable
|
The connectivity table for molecular clusters. |
clusters |
dict[int, Cluster]
|
A dictionary of detected clusters, keyed by cluster ID. |
mol_clt |
dict[int, int]
|
A mapping of molecule IDs to their respective cluster IDs. |
transition |
Transition
|
How the current clusters came from the previous frame's (on the first frame, every cluster is born). |
Initialize the tracker with the clusters of the current frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
universe
|
Universe
|
The MDAnalysis Universe object associated with the simulation. |
required |
config
|
MolClsConfig
|
The analysis configuration. |
required |
Source code in src/molclusters/tracker.py
update
¶
Reconcile the current frame's connected groups with the previous clusters.
This is the dominance algorithm, which keeps cluster ids stable while clusters grow, shrink, split and merge.
A connected group (subconn in the code, a
ConnectionTable._SubConnTable) is a set of molecules linked to each
other, directly or through other molecules, by the config's rules in the
current frame, and to nothing outside the set. Free (unlinked) molecules
form no connected group. A connected group has no id yet; a cluster is
what it becomes once this method gives it one, new or inherited from the
previous frame.
The connection table is rebuilt for the current frame, and the previous
clusters that the molecules of each connected group (ignored compositions
excluded) came from are counted (see _count_origins). Ids
are then assigned in two steps, each of which sees the whole frame:
- Each previous cluster picks its best group: the one holding the most of
its molecules, the purest on a tie (see
_best_groups). - Each connected group chosen by one or more previous clusters continues
the one that contributed the most molecules, the oldest on a tie (see
_get_older_cluster). A group chosen by nobody is a new cluster.
The usual events follow from these two rules:
- formation: a group of free molecules is chosen by nobody -> new;
- growth or shrinking: a group chosen by one cluster continues it;
- split: the cluster continues in its best fragment and the other fragments, chosen by nobody, are new;
- merge: several clusters choose the same group, one continues and the others die, even if they also left a remnant elsewhere;
- dissolution: a cluster that contributed at most one molecule to every group has no best group and dies.
So a mixed dimer (one molecule from each origin) is always new, and each id
continues in at most one group. Previous clusters that no connected group
continues are dropped, along with the mol_clt entries of molecules that
are now free. What happened is kept in transition: where each cluster's
molecules came from, which clusters are new, and which ended, merged into
another or dissolved.
Source code in src/molclusters/tracker.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | |