@@ -21,7 +21,10 @@ export
21
21
masses,
22
22
charges,
23
23
MollyCalculator,
24
- ASECalculator
24
+ ASECalculator,
25
+ NBodyInteraction,
26
+ SpecificInteraction,
27
+ PairwiseInteraction
25
28
26
29
const DefaultFloat = Float64
27
30
@@ -35,9 +38,10 @@ Base type for all n-body interactions. `N` denotes the body order
35
38
"""
36
39
abstract type NBodyInteraction{N} <: Interaction end
37
40
38
-
39
- abstract type SpecificInteraction <: Interaction end
40
- abstract type GeneralInteraction <: Interaction end
41
+ """
42
+ Base type for all specific interactions. `N` denotes number of atoms in the interaction.
43
+ """
44
+ abstract type SpecificInteraction{N} <: Interaction end
41
45
42
46
"""
43
47
Type alias for pairwise interactions
@@ -51,7 +55,7 @@ const PairwiseInteraction = NBodyInteraction{2}
51
55
52
56
A list of specific interactions that involve one atom such as position restraints.
53
57
"""
54
- struct InteractionList1Atoms{I, T} <: SpecificInteraction
58
+ struct InteractionList1Atoms{I, T} <: SpecificInteraction{1}
55
59
is:: I
56
60
inters:: T
57
61
types:: Vector{String}
64
68
65
69
A list of specific interactions that involve two atoms such as bond potentials.
66
70
"""
67
- struct InteractionList2Atoms{I, T} <: SpecificInteraction
71
+ struct InteractionList2Atoms{I, T} <: SpecificInteraction{2}
68
72
is:: I
69
73
js:: I
70
74
inters:: T
78
82
79
83
A list of specific interactions that involve three atoms such as bond angle potentials.
80
84
"""
81
- struct InteractionList3Atoms{I, T} <: SpecificInteraction
85
+ struct InteractionList3Atoms{I, T} <: SpecificInteraction{3}
82
86
is:: I
83
87
js:: I
84
88
ks:: I
93
97
94
98
A list of specific interactions that involve four atoms such as torsion potentials.
95
99
"""
96
- struct InteractionList4Atoms{I, T} <: SpecificInteraction
100
+ struct InteractionList4Atoms{I, T} <: SpecificInteraction{4}
97
101
is:: I
98
102
js:: I
99
103
ks:: I
@@ -636,42 +640,27 @@ Convenience constructor for `System` that takes all interactions in one tuple.
636
640
These are passed through the `interactions` kwarg.
637
641
"""
638
642
function System (;
639
- atoms,
640
- coords,
641
- boundary,
642
- velocities= nothing ,
643
- atoms_data= [],
644
- topology= nothing ,
645
643
interactions= (),
646
- constraints= (),
647
- neighbor_finder= NoNeighborFinder (),
648
- loggers= (),
649
- force_units= u " kJ * mol^-1 * nm^-1" ,
650
- energy_units= u " kJ * mol^-1" ,
651
- k= default_k (energy_units),
652
- data= nothing )
644
+ kwargs...
645
+ )
653
646
654
- general_inters = filter (i -> i isa GeneralInteraction, interactions)
655
- pairwise_inters = filter (i -> i isa PairwiseInteraction, interactions)
656
- specific_inters = filter (i -> i isa SpecificInteraction, interactions)
647
+ pairwise_inter_idxs = findall (i -> i isa PairwiseInteraction, interactions)
648
+ specific_inter_idxs = findall (i -> i isa SpecificInteraction, interactions)
649
+ nbody_inter_idxs = findall (i -> i isa NBodyInteraction, interactions)
650
+
651
+ length (nbody_inter_idxs) > length (pairwise_inters_idxs) || error (" Molly does not currently support n-body potentials beyond pair." )
652
+
653
+ # All remaining interactions assumed to be general
654
+ idxs = trues (length (interactions))
655
+ idxs[pairwise_inter_idxs] .= false
656
+ idxs[specific_inter_idxs] .= false
657
+ general_inters = interactions[idxs]
657
658
658
659
return System (
659
- atoms= atoms,
660
- coords= coords,
661
- boundary= boundary,
662
- velocities= velocities,
663
- atoms_data= atoms_data,
664
- topology= topology,
665
- pairwise_inters= pairwise_inters,
666
- specific_inter_lists= specific_inters,
660
+ pairwise_inters= pairwise_inters[pairwise_inter_idxs],
661
+ specific_inter_lists= specific_inters[specific_inter_idxs],
667
662
general_inters= general_inters,
668
- constraints= constraints,
669
- neighbor_finder= neighbor_finder,
670
- loggers= loggers,
671
- force_units= force_units,
672
- energy_units= energy_units,
673
- k= k,
674
- data= data,
663
+ kwargs...
675
664
)
676
665
677
666
end
0 commit comments