Skip to content

Species Inventory🔗

Various species types that can be declared and define the system being simulated.

Classes🔗

Brush 🔗

Bases: object

Class to store the location of a brushed surface. The brush density denotes the density of the affixed end of the polymer in space.

Parameters:

Name Type Description Default
name str

Unique name.

required
density ndarray

Density in space (of some corresponding grid) of the fixed segment of the polymer.

required

Attributes:

Name Type Description
name str

Unique name.

density ndarray

Spatial density of the attached brush end

Source code in polycomp/base.py
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
class Brush(object):
    """
    Class to store the location of a brushed surface. The brush density denotes the
    density of the affixed end of the polymer in space.

    Parameters
    ----------

    name
        Unique name.
    density
        Density in space (of some corresponding grid) of
        the fixed segment of the polymer.

    Attributes
    ----------

    name : str
        Unique name.
    density : cp.ndarray
        Spatial density of the attached brush end

    """

    def __init__(self, name: str, density: cp.ndarray) -> None:
        self.name = name
        self.density = density / cp.average(density)

    def __repr__(self):
        return self.name

Monomer 🔗

Bases: object

Class for the monomer of one species in the simulation.

Parameters:

Name Type Description Default
name str

Monomer identifier to be displayed publicly.

required
charge float

Monomer charge.

0
identity str

Monomer type (solvent or polymer).

'solvent'
has_volume bool

Whether the monomer occupies volume.

True

Attributes:

Name Type Description
name string

Unique monomer name.

charge float

Charge of the monomer.

identity string

Identity of the monomer, usually {polymer, solvent, salt, Nanoparticle}.

has_volume bool

Whether the monomer occupies volume.

Source code in polycomp/base.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Monomer(object):
    """
    Class for the monomer of one species in the simulation.

    Parameters
    ----------

    name
        Monomer identifier to be displayed publicly.
    charge
        Monomer charge.
    identity
        Monomer type (solvent or polymer).
    has_volume
        Whether the monomer occupies volume.

    Attributes
    ----------

    name : string
        Unique monomer name.
    charge : float
        Charge of the monomer.
    identity : string
        Identity of the monomer, usually {polymer, solvent, salt, Nanoparticle}.
    has_volume : bool
        Whether the monomer occupies volume.
    """

    def __init__(
        self,
        name: str,
        charge: float = 0,
        identity: str = "solvent",
        has_volume: bool = True,
    ) -> None:

        self.name = name
        self.has_volume = has_volume
        self.identity = identity
        self.charge = charge

    def __repr__(self):
        return self.name

Nanoparticle 🔗

Bases: object

Defines an inert nanoparticle with a fixed spatial density.

The position of the nanoparticle is fixed unless manually changed.

Parameters:

Name Type Description Default
name str

Unique name.

required
monomer_type Monomer

Monomer type associated with the nanoparticle in question (for FH interaction purposes).

required
density ndarray

Density in space (of some corresponding grid) of the nanoparticle.

required

Attributes:

Name Type Description
name str

Unique name.

density ndarray

Spatial density of the nanoparticle.

type Monomer

Monomer identity (for FH interaction purposes) of the nanoparticle.

Source code in polycomp/base.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
class Nanoparticle(object):
    """

    Defines an inert nanoparticle with a fixed spatial density.

    The position of the nanoparticle is fixed unless manually changed.

    Parameters
    ----------

    name
        Unique name.
    monomer_type
        Monomer type associated with the nanoparticle in question (for FH interaction
        purposes).
    density
        Density in space (of some corresponding grid) of the nanoparticle.

    Attributes
    ----------

    name : str
        Unique name.
    density : cp.ndarray
        Spatial density of the nanoparticle.
    type : Monomer
        Monomer identity (for FH interaction purposes) of the nanoparticle.

    """

    def __init__(self, name: str, monomer_type: Monomer, density: cp.ndarray) -> None:
        self.name = name
        self.density = density
        self.type = monomer_type

        self.type.identity = "Nanoparticle"

    def __repr__(self):
        return self.name

    def place_nps(self, positions: cp.ndarray) -> None:
        """
        Updates the density of the nanoparticle position

        Parameters
        ----------

        positions
            Desired new density profile for the nanoparticles in the system.
        """

        self.density = positions

Functions🔗

place_nps(positions: cp.ndarray) -> None 🔗

Updates the density of the nanoparticle position

Parameters:

Name Type Description Default
positions ndarray

Desired new density profile for the nanoparticles in the system.

required
Source code in polycomp/base.py
229
230
231
232
233
234
235
236
237
238
239
240
def place_nps(self, positions: cp.ndarray) -> None:
    """
    Updates the density of the nanoparticle position

    Parameters
    ----------

    positions
        Desired new density profile for the nanoparticles in the system.
    """

    self.density = positions

Polymer 🔗

Bases: object

Class to store all the information for one type of polymer.

Parameters:

Name Type Description Default
name str

Unique name.

required
total_length float

Total length along the polymer. (Only accurate if sum of block lengths is 1)

required
block_structure array - like

A list-like object of blocks defining the polymer architecture. Each block should be a list-like object of length 2, in the format (Monomer, float_fractional_length).

Example for a diblock: [(A_mon, 0.5), (B_mon, 0.5)]

required

Attributes:

Name Type Description
name string

Unique name of a polymer.

total_length float

Total length of the polymer for integration.

block_structure array - like

A list-like object of blocks defining the polymer architecture. Format is (Monomer, float_fractional_length).

struct ndarray

Array of Monomer objects representing linear polymer structure.

h_struct ndarray

Array of floats for the length of each section of the structure.

fastener Brush

Brush object indicating where the sequence is fastened. Fastening always occurs on the leading end.

Source code in polycomp/base.py
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
class Polymer(object):
    """
    Class to store all the information for one type of polymer.

    Parameters
    ----------

    name
        Unique name.
    total_length
        Total length along the polymer. (Only accurate if sum of block lengths is 1)
    block_structure : array-like
        A list-like object of blocks defining the polymer architecture. Each
        block should be a list-like object of length 2, in the format
        `(Monomer, float_fractional_length)`.

        Example for a diblock: `[(A_mon, 0.5), (B_mon, 0.5)]`

    Attributes
    ----------

    name : string
        Unique name of a polymer.
    total_length : float
        Total length of the polymer for integration.
    block_structure : array-like
        A list-like object of blocks defining the polymer architecture. Format is
        `(Monomer, float_fractional_length)`.
    struct : np.ndarray
        Array of Monomer objects representing linear polymer structure.
    h_struct : cp.ndarray
        Array of floats for the length of each section of the structure.
    fastener : Brush
        Brush object indicating where the sequence is fastened. Fastening always occurs
        on the leading end.

    """

    def __init__(
        self, name: str, total_length: float, block_structure: tuple, fastener=None
    ) -> None:

        super(Polymer, self).__init__()
        self.name = name
        self.total_length = total_length
        self.block_structure = block_structure

        self.struct = None
        # Identify which species are in any polymer
        for monomer in set(p[0] for p in self.block_structure):
            if monomer.identity != "polymer":
                monomer.identity = "polymer"

        self.identity = "entire_polymer"
        self.fastener = fastener

    def __repr__(self):
        return str(self.block_structure)

    def build_working_polymer(self, h: float, total_h: float) -> None:
        """
        Build the polymer structure that will be used for integration.

        Built-in method to construct a working polymer during integration
        according to parameters specific to the simulation run. Normally called
        automatically as part of system setup.

        Parameters
        ----------

        h
            Maximum integration segment length $\\Delta s$.
        total_h
            Total length of the polymer $s_P$.

        Raises
        ------

        ValueError:
            Raises an error if the polymer already has a built structure. At
            present, there is no reason that a polymer structure should be built
            more than once in a single simulation.
        """

        # Used to generate a string of h lengths and polymer species identities
        if self.struct is not None:
            raise ValueError("polymer structure should only be built once")
        hold_struct = []
        hold_h_struct = []
        end = 0.0

        # Splits up each block evenly while keeping h below target
        thresh = 1e-10
        for name_tuple in self.block_structure:
            end = name_tuple[1] * total_h
            units = int(end // h)
            if end % h > thresh:
                units += 1
            hold_struct = hold_struct + ([name_tuple[0]] * units)
            hold_h_struct = hold_h_struct + ([end / units] * units)

        self.struct = np.asarray(hold_struct)
        self.h_struct = cp.asarray(hold_h_struct, dtype="float64")
        return

Functions🔗

build_working_polymer(h: float, total_h: float) -> None 🔗

Build the polymer structure that will be used for integration.

Built-in method to construct a working polymer during integration according to parameters specific to the simulation run. Normally called automatically as part of system setup.

Parameters:

Name Type Description Default
h float

Maximum integration segment length \(\Delta s\).

required
total_h float

Total length of the polymer \(s_P\).

required

Raises:

Type Description
ValueError:

Raises an error if the polymer already has a built structure. At present, there is no reason that a polymer structure should be built more than once in a single simulation.

Source code in polycomp/base.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
def build_working_polymer(self, h: float, total_h: float) -> None:
    """
    Build the polymer structure that will be used for integration.

    Built-in method to construct a working polymer during integration
    according to parameters specific to the simulation run. Normally called
    automatically as part of system setup.

    Parameters
    ----------

    h
        Maximum integration segment length $\\Delta s$.
    total_h
        Total length of the polymer $s_P$.

    Raises
    ------

    ValueError:
        Raises an error if the polymer already has a built structure. At
        present, there is no reason that a polymer structure should be built
        more than once in a single simulation.
    """

    # Used to generate a string of h lengths and polymer species identities
    if self.struct is not None:
        raise ValueError("polymer structure should only be built once")
    hold_struct = []
    hold_h_struct = []
    end = 0.0

    # Splits up each block evenly while keeping h below target
    thresh = 1e-10
    for name_tuple in self.block_structure:
        end = name_tuple[1] * total_h
        units = int(end // h)
        if end % h > thresh:
            units += 1
        hold_struct = hold_struct + ([name_tuple[0]] * units)
        hold_h_struct = hold_h_struct + ([end / units] * units)

    self.struct = np.asarray(hold_struct)
    self.h_struct = cp.asarray(hold_h_struct, dtype="float64")
    return