dimer_index
Dimer indexing and symmetry equivalence for crystal structures.
This module provides data structures for tracking molecular dimers (pairs of molecules) and determining their symmetry equivalence.
There are two approaches: 1. Distance-based: Group dimers by matching distances (with tolerance) 2. Algebraic: Use group theory - dimers equivalent if a space group operation maps one to the other (no tolerance needed, exact algebraic comparison)
AlgebraicDimerEquivalenceClass
dataclass
A group of symmetry-equivalent dimers determined algebraically.
All dimers in this class are related by space group symmetry operations. Unlike DimerEquivalenceClass, equivalence is determined by exact algebraic comparison (no distance tolerance).
Attributes:
| Name | Type | Description |
|---|---|---|
representative |
AlgebraicDimerIndex
|
One representative dimer from the class |
member_indices |
list[int]
|
Indices of all dimers in this equivalence class |
multiplicity |
int
|
Orbit size (number of distinct images under group action) |
Source code in chmpy/crystal/dimer_index.py
AlgebraicDimerIndex
dataclass
Algebraic index for a molecular dimer using symop indices.
This class represents a dimer using algebraic molecule references (symop indices rather than instance indices). This enables exact equivalence checking via group theory without numerical tolerances.
The dimer is stored in canonical form where mol_a <= mol_b.
Attributes:
| Name | Type | Description |
|---|---|---|
mol_a |
AlgebraicMoleculeRef
|
Algebraic reference to first molecule (always <= mol_b) |
mol_b |
AlgebraicMoleculeRef
|
Algebraic reference to second molecule |
Source code in chmpy/crystal/dimer_index.py
create(mol_a, mol_b)
classmethod
Create an AlgebraicDimerIndex with automatic canonical ordering.
Source code in chmpy/crystal/dimer_index.py
involves_molecule_type(asym_mol_idx)
Check if this dimer involves a specific molecule type.
AlgebraicMoleculeRef
dataclass
Algebraic reference to a molecule instance in the crystal.
Unlike MoleculeRef which uses instance_idx (position in unit cell), this uses symop_idx which is the index of the symmetry operation that generated this molecule from the asymmetric unit. This enables purely algebraic symmetry operations using the group multiplication table.
Attributes:
| Name | Type | Description |
|---|---|---|
asym_mol_idx |
int
|
Index of the unique molecule type in asymmetric unit |
symop_idx |
int
|
Index into space group's symmetry operation list |
cell |
tuple[int, int, int]
|
(h, k, l) periodic cell offset from reference cell |
Source code in chmpy/crystal/dimer_index.py
__ge__(other)
__gt__(other)
__le__(other)
DimerEquivalenceClass
dataclass
A group of symmetry-equivalent dimers.
All dimers in this class are related by space group symmetry operations.
Attributes:
| Name | Type | Description |
|---|---|---|
representative |
DimerIndex
|
One representative dimer from the class |
members |
list[DimerIndex]
|
All dimers in this equivalence class |
multiplicity |
int
|
Number of equivalent dimers |
metadata |
dict
|
Optional metadata (e.g., central/neighbor types for non-permutative) |
Source code in chmpy/crystal/dimer_index.py
central_mol_type
property
Central molecule type (for non-permutative enumeration).
distance
property
Distance of dimers in this class.
neighbor_mol_type
property
Neighbor molecule type (for non-permutative enumeration).
DimerIndex
dataclass
Canonical index for a molecular dimer (pair of molecules).
The dimer is stored in canonical form where mol_a <= mol_b. This ensures each dimer has a unique representation.
Attributes:
| Name | Type | Description |
|---|---|---|
mol_a |
MoleculeRef
|
Reference to first molecule (always <= mol_b) |
mol_b |
MoleculeRef
|
Reference to second molecule |
distance |
float
|
Center-to-center distance between molecules |
Source code in chmpy/crystal/dimer_index.py
create(mol_a, mol_b, distance)
classmethod
Create a DimerIndex with automatic canonical ordering.
Source code in chmpy/crystal/dimer_index.py
involves_molecule_type(asym_mol_idx)
Check if this dimer involves a specific molecule type.
DimerList
dataclass
List of all unique dimers within a cutoff distance.
Attributes:
| Name | Type | Description |
|---|---|---|
dimers |
list[DimerIndex]
|
List of DimerIndex objects |
n_dimers |
int
|
Total number of unique dimers |
cutoff |
float
|
Distance cutoff used |
Source code in chmpy/crystal/dimer_index.py
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 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
from_crystal(crystal, mol_orbit, cutoff=10.0)
classmethod
Build a list of all unique dimers within cutoff distance.
Uses molecule centroids to determine neighbor pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crystal
|
Crystal
|
The crystal structure |
required |
mol_orbit
|
MoleculeOrbitTable
|
MoleculeOrbitTable with molecule instances |
required |
cutoff
|
float
|
Maximum center-to-center distance |
10.0
|
Returns:
| Type | Description |
|---|---|
DimerList
|
DimerList with all unique dimers |
Source code in chmpy/crystal/dimer_index.py
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 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
get_dimers_involving(asym_mol_idx)
Get all dimers involving a specific molecule type.
get_heterodimers()
get_homodimers()
group_by_distance(tolerance=0.01)
Group dimers by distance within tolerance.
Returns:
| Type | Description |
|---|---|
list[tuple[float, list[DimerIndex]]]
|
List of (distance, dimers) tuples, sorted by distance |
Source code in chmpy/crystal/dimer_index.py
unique_distances(tolerance=0.01)
Get list of unique dimer distances within tolerance.
MolecularCosetTable
dataclass
Mapping between symop indices and unit cell molecules.
When Z' < 1, multiple symops can generate the same molecule (they differ by the site symmetry). This table tracks which molecule each symop generates and provides a canonical symop for each molecule.
Attributes:
| Name | Type | Description |
|---|---|---|
n_symops |
int
|
Number of space group operations |
n_uc_molecules |
int
|
Number of molecules in unit cell |
symop_to_mol |
ndarray
|
(n_symops,) symop_idx -> uc_mol_idx |
mol_to_canonical_symop |
ndarray
|
(n_uc_molecules,) uc_mol_idx -> canonical symop_idx |
site_symmetry_order |
ndarray
|
(n_uc_molecules,) order of site symmetry for each molecule |
Source code in chmpy/crystal/dimer_index.py
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 | |
from_crystal(crystal, mol_orbit, sg_table)
classmethod
Build the molecular coset table from crystal structure.
For each symop g, we determine which UC molecule results when g is applied to the asymmetric unit. This is done by applying g to a reference molecule's centroid and finding which UC molecule centroid it maps to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crystal
|
Crystal
|
The crystal structure |
required |
mol_orbit
|
MoleculeOrbitTable
|
MoleculeOrbitTable with molecule instances |
required |
sg_table
|
SpaceGroupTable
|
SpaceGroupTable for the space group |
required |
Returns:
| Type | Description |
|---|---|
MolecularCosetTable
|
MolecularCosetTable with symop-to-molecule mappings |
Source code in chmpy/crystal/dimer_index.py
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 | |
normalize_symop(symop_idx)
Normalize a symop index to (uc_mol_idx, canonical_symop_idx).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symop_idx
|
int
|
The symop index to normalize |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
Tuple of (uc_mol_idx, canonical_symop_idx) |
Source code in chmpy/crystal/dimer_index.py
MoleculeRef
dataclass
Reference to a molecule instance in the crystal.
Attributes:
| Name | Type | Description |
|---|---|---|
asym_mol_idx |
int
|
Index of the unique molecule type |
instance_idx |
int
|
Index of this instance in MoleculeOrbitTable |
cell_offset |
tuple[int, int, int]
|
(h, k, l) periodic cell offset from reference cell |
Source code in chmpy/crystal/dimer_index.py
__ge__(other)
__gt__(other)
__le__(other)
apply_symop_to_algebraic_dimer(dimer, symop_idx, sg_table, coset_table=None)
Apply a space group operation to an algebraic dimer.
This transforms both molecules in the dimer and returns the result in canonical form (mol_a <= mol_b).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimer
|
AlgebraicDimerIndex
|
The dimer to transform |
required |
symop_idx
|
int
|
Index of the symop to apply |
required |
sg_table
|
SpaceGroupTable
|
The precomputed space group table |
required |
coset_table
|
MolecularCosetTable | None
|
Optional MolecularCosetTable for symop normalization |
None
|
Returns:
| Type | Description |
|---|---|
AlgebraicDimerIndex
|
Transformed AlgebraicDimerIndex in canonical form |
Source code in chmpy/crystal/dimer_index.py
apply_symop_to_algebraic_mol(mol, symop_idx, sg_table, coset_table=None)
Apply a space group operation to an algebraic molecule reference.
This is a purely algebraic operation using the group multiplication table: - The new symop index is computed via the Cayley table - The cell offset is transformed by the rotation part of the symop - If coset_table is provided, normalizes the symop to the canonical one for the resulting molecule (important for Z' < 1 cases)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mol
|
AlgebraicMoleculeRef
|
The molecule reference to transform |
required |
symop_idx
|
int
|
Index of the symop to apply |
required |
sg_table
|
SpaceGroupTable
|
The precomputed space group table |
required |
coset_table
|
MolecularCosetTable | None
|
Optional MolecularCosetTable for symop normalization |
None
|
Returns:
| Type | Description |
|---|---|
AlgebraicMoleculeRef
|
Transformed AlgebraicMoleculeRef |
Source code in chmpy/crystal/dimer_index.py
build_algebraic_dimer_list(crystal, mol_orbit, cutoff=10.0)
Build a list of algebraic dimers from the crystal structure.
This creates AlgebraicDimerIndex objects that use symop indices rather than instance indices, enabling algebraic symmetry operations.
For proper dimer enumeration, we only consider dimers around ONE reference molecule per unique molecule type (the one generated by the identity symop). This ensures we don't count symmetry-equivalent dimers multiple times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crystal
|
Crystal
|
The crystal structure |
required |
mol_orbit
|
MoleculeOrbitTable
|
MoleculeOrbitTable with molecule instances |
required |
cutoff
|
float
|
Maximum center-to-center distance |
10.0
|
Returns:
| Type | Description |
|---|---|
list[AlgebraicDimerIndex]
|
Tuple of: |
list[float]
|
|
SpaceGroupTable
|
|
MolecularCosetTable
|
|
tuple[list[AlgebraicDimerIndex], list[float], SpaceGroupTable, MolecularCosetTable]
|
|
Source code in chmpy/crystal/dimer_index.py
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 | |
canonical_dimer_representative(dimer, sg_table, coset_table=None)
Find the canonical representative of a dimer under group action.
The canonical representative is the lexicographically smallest element of the orbit of the dimer under all space group operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimer
|
AlgebraicDimerIndex
|
The dimer to canonicalize |
required |
sg_table
|
SpaceGroupTable
|
SpaceGroupTable for the space group |
required |
coset_table
|
MolecularCosetTable | None
|
Optional MolecularCosetTable for symop normalization |
None
|
Returns:
| Type | Description |
|---|---|
AlgebraicDimerIndex
|
The canonical representative (smallest in orbit) |
Source code in chmpy/crystal/dimer_index.py
compute_dimer_orbit_size(dimer, sg_table, coset_table=None)
Compute the orbit size of a dimer under the space group action.
This is the number of distinct dimers obtained by applying all space group operations. This represents the multiplicity - how many symmetry-equivalent copies of this dimer exist in the crystal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimer
|
AlgebraicDimerIndex
|
The dimer to compute orbit size for |
required |
sg_table
|
SpaceGroupTable
|
SpaceGroupTable for the space group |
required |
coset_table
|
MolecularCosetTable | None
|
Optional MolecularCosetTable for symop normalization |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Size of the orbit (number of distinct images) |
Source code in chmpy/crystal/dimer_index.py
find_algebraic_equivalence_classes(dimers, sg_table, coset_table=None)
Group dimers by symmetry equivalence using pure algebra.
Two dimers are equivalent if they have the same canonical representative under the space group action. This uses the group multiplication table for exact comparison - no numerical tolerances needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimers
|
list[AlgebraicDimerIndex]
|
List of algebraic dimer indices |
required |
sg_table
|
SpaceGroupTable
|
SpaceGroupTable for the space group |
required |
coset_table
|
MolecularCosetTable | None
|
Optional MolecularCosetTable for symop normalization (important for Z' < 1 cases) |
None
|
Returns:
| Type | Description |
|---|---|
list[list[int]]
|
Tuple of: |
list[int]
|
|
tuple[list[list[int]], list[int]]
|
|
Source code in chmpy/crystal/dimer_index.py
find_dimers_around_molecule(crystal, mol_orbit, ref_mol_idx=0, cutoff=10.0)
Find all dimers surrounding a single reference molecule.
This is the correct approach for dimer enumeration: pick ONE central molecule and find all its neighbors within cutoff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crystal
|
Crystal
|
The crystal structure |
required |
mol_orbit
|
MoleculeOrbitTable
|
MoleculeOrbitTable with molecule instances |
required |
ref_mol_idx
|
int
|
Index of reference molecule in unit cell (default: 0) |
0
|
cutoff
|
float
|
Maximum center-to-center distance |
10.0
|
Returns:
| Type | Description |
|---|---|
list[DimerIndex]
|
List of DimerIndex objects for all dimers around the reference |
Source code in chmpy/crystal/dimer_index.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 | |
find_symmetry_unique_dimers(crystal, mol_orbit, cutoff=10.0, distance_tolerance=0.01, permutative=True)
Find symmetry-unique dimers within cutoff distance.
For each symmetry-unique molecule, find all dimers surrounding it and group by equivalence. Two dimers are equivalent if they have the same separation (within tolerance) - this matches the existing chmpy approach using geometric comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crystal
|
Crystal
|
The crystal structure |
required |
mol_orbit
|
MoleculeOrbitTable
|
MoleculeOrbitTable with molecule instances |
required |
cutoff
|
float
|
Maximum center-to-center distance |
10.0
|
distance_tolerance
|
float
|
Tolerance for comparing distances |
0.01
|
permutative
|
bool
|
If True (default), A-B and B-A dimers are equivalent. If False, distinguish dimers by which molecule type is the "central" molecule. This matters for heterodimers where you care about directionality (e.g., donor-acceptor interactions). |
True
|
Returns:
| Type | Description |
|---|---|
list[DimerEquivalenceClass]
|
Tuple of: |
list[tuple[int, DimerIndex]]
|
|
tuple[list[DimerEquivalenceClass], list[tuple[int, DimerIndex]]]
|
|
Source code in chmpy/crystal/dimer_index.py
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 | |
find_symmetry_unique_dimers_algebraic(crystal, mol_orbit, cutoff=10.0)
Find symmetry-unique dimers using algebraic group theory.
This is the algebraic alternative to find_symmetry_unique_dimers(). It determines equivalence by applying all space group operations and checking for exact algebraic equality - no distance tolerances needed.
For Z' < 1 crystals (molecules on special positions), this properly handles the site symmetry by normalizing symop indices to canonical representatives for each molecule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crystal
|
Crystal
|
The crystal structure |
required |
mol_orbit
|
MoleculeOrbitTable
|
MoleculeOrbitTable with molecule instances |
required |
cutoff
|
float
|
Maximum center-to-center distance |
10.0
|
Returns:
| Type | Description |
|---|---|
list[AlgebraicDimerEquivalenceClass]
|
Tuple of: |
list[AlgebraicDimerIndex]
|
|
list[float]
|
|
tuple[list[AlgebraicDimerEquivalenceClass], list[AlgebraicDimerIndex], list[float]]
|
|
Source code in chmpy/crystal/dimer_index.py
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 | |
normalize_algebraic_dimer(dimer, sg_table)
Normalize an algebraic dimer to a canonical representative.
Normalization ensures: 1. mol_a <= mol_b (lexicographic ordering) 2. The "smaller" molecule is at cell (0,0,0)
This is necessary because dimers that differ only by a lattice translation are equivalent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimer
|
AlgebraicDimerIndex
|
The dimer to normalize |
required |
sg_table
|
SpaceGroupTable
|
The precomputed space group table |
required |
Returns:
| Type | Description |
|---|---|
AlgebraicDimerIndex
|
Normalized AlgebraicDimerIndex |