1.. index:: compute reduce/chunk 2 3compute reduce/chunk command 4============================ 5 6Syntax 7"""""" 8 9.. parsed-literal:: 10 11 compute ID group-ID reduce/chunk chunkID mode input1 input2 ... 12 13* ID, group-ID are documented in :doc:`compute <compute>` command 14* reduce/chunk = style name of this compute command 15* chunkID = ID of :doc:`compute chunk/atom <compute_chunk_atom>` command 16* mode = *sum* or *min* or *max* 17* one or more inputs can be listed 18* input = c_ID, c_ID[N], f_ID, f_ID[N], v_ID 19 20 .. parsed-literal:: 21 22 c_ID = per-atom vector calculated by a compute with ID 23 c_ID[I] = Ith column of per-atom array calculated by a compute with ID, I can include wildcard (see below) 24 f_ID = per-atom vector calculated by a fix with ID 25 f_ID[I] = Ith column of per-atom array calculated by a fix with ID, I can include wildcard (see below) 26 v_name = per-atom vector calculated by an atom-style variable with name 27 28Examples 29"""""""" 30 31.. code-block:: LAMMPS 32 33 compute 1 all reduce/chunk mychunk min c_cluster 34 35Description 36""""""""""" 37 38Define a calculation that reduces one or more per-atom vectors into 39per-chunk values. This can be useful for diagnostic output. Or when 40used in conjunction with the :doc:`compute chunk/spread/atom <compute_chunk_spread_atom>` command it can be 41used to create per-atom values that induce a new set of chunks with a 42second :doc:`compute chunk/atom <compute_chunk_atom>` command. An 43example is given below. 44 45In LAMMPS, chunks are collections of atoms defined by a :doc:`compute chunk/atom <compute_chunk_atom>` command, which assigns each atom 46to a single chunk (or no chunk). The ID for this command is specified 47as chunkID. For example, a single chunk could be the atoms in a 48molecule or atoms in a spatial bin. See the :doc:`compute chunk/atom <compute_chunk_atom>` and :doc:`Howto chunk <Howto_chunk>` 49doc pages for details of how chunks can be defined and examples of how 50they can be used to measure properties of a system. 51 52For each atom, this compute accesses its chunk ID from the specified 53*chunkID* compute. The per-atom value from an input contributes 54to a per-chunk value corresponding the the chunk ID. 55 56The reduction operation is specified by the *mode* setting and is 57performed over all the per-atom values from the atoms in each chunk. 58The *sum* option adds the pre-atom values to a per-chunk total. The 59*min* or *max* options find the minimum or maximum value of the 60per-atom values for each chunk. 61 62Note that only atoms in the specified group contribute to the 63reduction operation. If the *chunkID* compute returns a 0 for the 64chunk ID of an atom (i.e. the atom is not in a chunk defined by the 65:doc:`compute chunk/atom <compute_chunk_atom>` command), that atom will 66also not contribute to the reduction operation. An input that is a 67compute or fix may define its own group which affects the quantities 68it returns. For example, a compute with return a zero value for atoms 69that are not in the group specified for that compute. 70 71Each listed input is operated on independently. Each input can be the 72result of a :doc:`compute <compute>` or :doc:`fix <fix>` or the evaluation 73of an atom-style :doc:`variable <variable>`. 74 75Note that for values from a compute or fix, the bracketed index I can 76be specified using a wildcard asterisk with the index to effectively 77specify multiple values. This takes the form "\*" or "\*n" or "n\*" or 78"m\*n". If N = the size of the vector (for *mode* = scalar) or the 79number of columns in the array (for *mode* = vector), then an asterisk 80with no numeric values means all indices from 1 to N. A leading 81asterisk means all indices from 1 to n (inclusive). A trailing 82asterisk means all indices from n to N (inclusive). A middle asterisk 83means all indices from m to n (inclusive). 84 85Using a wildcard is the same as if the individual columns of the array 86had been listed one by one. E.g. these 2 compute reduce/chunk 87commands are equivalent, since the :doc:`compute property/chunk <compute_property_chunk>` command creates a per-atom 88array with 3 columns: 89 90.. code-block:: LAMMPS 91 92 compute prop all property/atom vx vy vz 93 compute 10 all reduce/chunk mychunk max c_prop[*] 94 compute 10 all reduce/chunk mychunk max c_prop[1] c_prop[2] c_prop[3] 95 96---------- 97 98Here is an example of using this compute, in conjunction with the 99compute chunk/spread/atom command to identify self-assembled micelles. 100The commands below can be added to the examples/in.micelle script. 101 102Imagine a collection of polymer chains or small molecules with 103hydrophobic end groups. All the hydrophobic (HP) atoms are assigned 104to a group called "phobic". 105 106These commands will assign a unique cluster ID to all HP atoms within 107a specified distance of each other. A cluster will contain all HP 108atoms in a single molecule, but also the HP atoms in nearby molecules, 109e.g. molecules that have clumped to form a micelle due to the 110attraction induced by the hydrophobicity. The output of the 111chunk/reduce command will be a cluster ID per chunk (molecule). 112Molecules with the same cluster ID are in the same micelle. 113 114.. code-block:: LAMMPS 115 116 group phobic type 4 # specific to in.micelle model 117 compute cluster phobic cluster/atom 2.0 118 compute cmol all chunk/atom molecule 119 compute reduce phobic reduce/chunk cmol min c_cluster 120 121This per-chunk info could be output in at least two ways: 122 123.. code-block:: LAMMPS 124 125 fix 10 all ave/time 1000 1 1000 c_reduce file tmp.phobic mode vector 126 127 compute spread all chunk/spread/atom cmol c_reduce 128 dump 1 all custom 1000 tmp.dump id type mol x y z c_cluster c_spread 129 dump_modify 1 sort id 130 131In the first case, each snapshot in the tmp.phobic file will contain 132one line per molecule. Molecules with the same value are in the same 133micelle. In the second case each dump snapshot contains all atoms, 134each with a final field with the cluster ID of the micelle that the HP 135atoms of that atom's molecule belong to. 136 137The result from compute chunk/spread/atom can be used to define a new 138set of chunks, where all the atoms in all the molecules in the same 139micelle are assigned to the same chunk, i.e. one chunk per micelle. 140 141.. code-block:: LAMMPS 142 143 compute micelle all chunk/atom c_spread compress yes 144 145Further analysis on a per-micelle basis can now be performed using any 146of the per-chunk computes listed on the :doc:`Howto chunk <Howto_chunk>` 147doc page. E.g. count the number of atoms in each micelle, calculate 148its center or mass, shape (moments of inertia), radius of gyration, 149etc. 150 151.. code-block:: LAMMPS 152 153 compute prop all property/chunk micelle count 154 fix 20 all ave/time 1000 1 1000 c_prop file tmp.micelle mode vector 155 156Each snapshot in the tmp.micelle file will have one line per micelle 157with its count of atoms, plus a first line for a chunk with all the 158solvent atoms. By the time 50000 steps have elapsed there are a 159handful of large micelles. 160 161---------- 162 163Output info 164""""""""""" 165 166This compute calculates a global vector if a single input value is 167specified, otherwise a global array is output. The number of columns 168in the array is the number of inputs provided. The length of the 169vector or the number of vector elements or array rows = the number of 170chunks *Nchunk* as calculated by the specified :doc:`compute chunk/atom <compute_chunk_atom>` command. The vector or array can 171be accessed by any command that uses global values from a compute as 172input. See the :doc:`Howto output <Howto_output>` page for an 173overview of LAMMPS output options. 174 175The per-atom values for the vector or each column of the array will be 176in whatever :doc:`units <units>` the corresponding input value is in. 177The vector or array values are "intensive". 178 179Restrictions 180"""""""""""" 181 none 182 183Related commands 184"""""""""""""""" 185 186:doc:`compute chunk/atom <compute_chunk_atom>`, :doc:`compute reduce <compute_reduce>`, :doc:`compute chunk/spread/atom <compute_chunk_spread_atom>` 187 188Default 189""""""" 190 191none 192