def __init__(self, order_parameters, lattice_vectors, phases, interface_width, name):
        # initialize the base class
        force._force.__init__(self, name);

        self.cpp_force = None;

        cpp_order_parameters = hoomd.std_vector_scalar()
        for l in order_parameters:
            cpp_order_parameters.append(l)

        cpp_lattice_vectors = _external.std_vector_int3()
        for l in lattice_vectors:
            if len(l) != 3:
                globals.msg.error("List of input lattice vectors not a list of triples.\n")
                raise RuntimeError('Error creating external ordering potential.')
            cpp_lattice_vectors.append(hoomd.make_int3(l[0], l[1], l[2]))

        cpp_phases = hoomd.std_vector_scalar()
        for l in phases:
            cpp_phases.append(l)

        cpp_interface_width = float(interface_width)

        if not globals.exec_conf.isCUDAEnabled():
            self.cpp_force = _external.OrderingExternal(globals.system_definition, cpp_order_parameters, cpp_lattice_vectors, cpp_phases, cpp_interface_width, self.name)
        else:
            self.cpp_force = _external.OrderingExternalGPU(globals.system_definition, cpp_order_parameters, cpp_lattice_vectors, cpp_phases, cpp_interface_width, self.name)

        globals.system.addCompute(self.cpp_force, self.force_name)

        self.enabled = True;
Esempio n. 2
0
    def _make_cpp_decomposition(self, box):
        # if the box is uniform in all directions, just use these values
        if self.uniform_x and self.uniform_y and self.uniform_z:
            self.cpp_dd = hoomd.DomainDecomposition(globals.exec_conf, box.getL(), self.nx, self.ny, self.nz, not globals.options.onelevel)
            return self.cpp_dd

        # otherwise, make the fractional decomposition
        try:
            fxs = hoomd.std_vector_scalar()
            fys = hoomd.std_vector_scalar()
            fzs = hoomd.std_vector_scalar()

            # if uniform, correct the fractions to be uniform as well
            if self.uniform_x and self.nx > 0:
                self.x = [1.0/self.nx]*(self.nx-1)
            if self.uniform_y and self.ny > 0:
                self.y = [1.0/self.ny]*(self.ny-1)
            if self.uniform_z and self.nz > 0:
                self.z = [1.0/self.nz]*(self.nz-1)

            sum_x = sum_y = sum_z = 0.0
            tol = 1.0e-5
            for i in self.x:
                if i <= -tol or i >= 1.0 - tol:
                    globals.msg.error("comm.decomposition: fraction must be between 0.0 and 1.0\n")
                    raise RuntimeError("Fractional decomposition must be between 0.0 and 1.0")
                fxs.append(i)
                sum_x += i
            if sum_x >= 1.0 - tol or sum_x <= -tol:
                globals.msg.error("comm.decomposition: fraction must be between 0.0 and 1.0\n")
                raise RuntimeError("Sum of decomposition in x must lie between 0.0 and 1.0")

            for i in self.y:
                if i <= -tol or i >= 1.0 - tol:
                    globals.msg.error("comm.decomposition: fraction must be between 0.0 and 1.0\n")
                    raise RuntimeError("Fractional decomposition must be between 0.0 and 1.0")
                fys.append(i)
                sum_y += i
            if sum_y >= 1.0 - tol or sum_y <= -tol:
                globals.msg.error("comm.decomposition: fraction must be between 0.0 and 1.0\n")
                raise RuntimeError("Sum of decomposition in y must lie between 0.0 and 1.0")

            for i in self.z:
                if i <= -tol or i >= 1.0 - tol:
                    globals.msg.error("comm.decomposition: fraction must be between 0.0 and 1.0\n")
                    raise RuntimeError("Fractional decomposition must be between 0.0 and 1.0")
                fzs.append(i)
                sum_z += i
            if sum_z >= 1.0 - tol or sum_z <= -tol:
                globals.msg.error("comm.decomposition: fraction must be between 0.0 and 1.0\n")
                raise RuntimeError("Sum of decomposition in z must lie between 0.0 and 1.0")

            self.cpp_dd = hoomd.DomainDecomposition(globals.exec_conf, box.getL(), fxs, fys, fzs)
            return self.cpp_dd

        except TypeError as te:
            globals.msg.error("Fractional cuts must be iterable (list, tuple, etc.)\n")
            raise te
Esempio n. 3
0
    def update_angle_table(self, atype, func, coeff):
        # allocate arrays to store V and F
        Vtable = hoomd.std_vector_scalar()
        Ttable = hoomd.std_vector_scalar()

        # calculate dth
        dth = math.pi / float(self.width - 1)

        # evaluate each point of the function
        for i in range(0, self.width):
            theta = dth * i
            (V, T) = func(theta, **coeff)

            # fill out the tables
            Vtable.append(V)
            Ttable.append(T)

        # pass the tables on to the underlying cpp compute
        self.cpp_force.setTable(atype, Vtable, Ttable)
Esempio n. 4
0
    def update_dihedral_table(self, atype, func, coeff):
        # allocate arrays to store V and F
        Vtable = hoomd.std_vector_scalar();
        Ttable = hoomd.std_vector_scalar();

        # calculate dth
        dth = 2.0*math.pi / float(self.width-1);

        # evaluate each point of the function
        for i in range(0, self.width):
            theta = -math.pi+dth * i;
            (V,T) = func(theta, **coeff);

            # fill out the tables
            Vtable.append(V);
            Ttable.append(T);

        # pass the tables on to the underlying cpp compute
        self.cpp_force.setTable(atype, Vtable, Ttable);
Esempio n. 5
0
    def update_bond_table(self, btype, func, rmin, rmax, coeff):
        # allocate arrays to store V and F
        Vtable = hoomd.std_vector_scalar()
        Ftable = hoomd.std_vector_scalar()

        # calculate dr
        dr = (rmax - rmin) / float(self.width - 1)

        # evaluate each point of the function
        for i in range(0, self.width):
            r = rmin + dr * i
            (V, F) = func(r, rmin, rmax, **coeff)

            # fill out the tables
            Vtable.append(V)
            Ftable.append(F)

        # pass the tables on to the underlying cpp compute
        self.cpp_force.setTable(btype, Vtable, Ftable, rmin, rmax)
Esempio n. 6
0
    def update_bond_table(self, btype, func, rmin, rmax, coeff):
        # allocate arrays to store V and F
        Vtable = hoomd.std_vector_scalar();
        Ftable = hoomd.std_vector_scalar();

        # calculate dr
        dr = (rmax - rmin) / float(self.width-1);

        # evaluate each point of the function
        for i in range(0, self.width):
            r = rmin + dr * i;
            (V,F) = func(r, rmin, rmax, **coeff);

            # fill out the tables
            Vtable.append(V);
            Ftable.append(F);

        # pass the tables on to the underlying cpp compute
        self.cpp_force.setTable(btype, Vtable, Ftable, rmin, rmax);
    def __init__(self, mode, lattice_vectors, name=None, sigma=1.0, offs=0.0):
        util.print_status_line()

        if name is not None:
            name = "_" + name
            suffix = name
        else:
            suffix = ""

        _collective_variable.__init__(self, sigma, name)

        if len(lattice_vectors) == 0:
            globals.msg.error(
                "cv.lamellar: List of supplied latice vectors is empty.\n")
            raise RuntimeEror('Error creating collective variable.')

        if type(mode) != type(dict()):
            globals.msg.error(
                "cv.lamellar: Mode amplitudes specified incorrectly.\n")
            raise RuntimeEror('Error creating collective variable.')

        cpp_mode = hoomd.std_vector_scalar()
        for i in range(
                0,
                globals.system_definition.getParticleData().getNTypes()):
            t = globals.system_definition.getParticleData().getNameByType(i)

            if t not in mode.keys():
                globals.msg.error(
                    "cv.lamellar: Missing mode amplitude for particle type " +
                    t + ".\n")
                raise RuntimeEror('Error creating collective variable.')
            cpp_mode.append(mode[t])

        cpp_lattice_vectors = _metadynamics.std_vector_int3()
        for l in lattice_vectors:
            if len(l) != 3:
                globals.msg.error(
                    "cv.lamellar: List of input lattice vectors not a list of triples.\n"
                )
                raise RuntimeError('Error creating collective variable.')
            cpp_lattice_vectors.append(hoomd.make_int3(l[0], l[1], l[2]))

        if not globals.exec_conf.isCUDAEnabled():
            self.cpp_force = _metadynamics.LamellarOrderParameter(
                globals.system_definition, cpp_mode, cpp_lattice_vectors, offs,
                suffix)
        else:
            self.cpp_force = _metadynamics.LamellarOrderParameterGPU(
                globals.system_definition, cpp_mode, cpp_lattice_vectors, offs,
                suffix)

        globals.system.addCompute(self.cpp_force, self.force_name)
    def __init__(self, order_parameters, lattice_vectors, phases,
                 interface_width, name):
        # initialize the base class
        force._force.__init__(self, name)

        self.cpp_force = None

        cpp_order_parameters = hoomd.std_vector_scalar()
        for l in order_parameters:
            cpp_order_parameters.append(l)

        cpp_lattice_vectors = _external.std_vector_int3()
        for l in lattice_vectors:
            if len(l) != 3:
                globals.msg.error(
                    "List of input lattice vectors not a list of triples.\n")
                raise RuntimeError(
                    'Error creating external ordering potential.')
            cpp_lattice_vectors.append(hoomd.make_int3(l[0], l[1], l[2]))

        cpp_phases = hoomd.std_vector_scalar()
        for l in phases:
            cpp_phases.append(l)

        cpp_interface_width = float(interface_width)

        if not globals.exec_conf.isCUDAEnabled():
            self.cpp_force = _external.OrderingExternal(
                globals.system_definition, cpp_order_parameters,
                cpp_lattice_vectors, cpp_phases, cpp_interface_width,
                self.name)
        else:
            self.cpp_force = _external.OrderingExternalGPU(
                globals.system_definition, cpp_order_parameters,
                cpp_lattice_vectors, cpp_phases, cpp_interface_width,
                self.name)

        globals.system.addCompute(self.cpp_force, self.force_name)

        self.enabled = True
    def __init__(self, filename, mode, lattice_vectors, phases, grid, period=1, endtime=1, overwrite=False):
        util.print_status_line();
    
        # initialize base class
        _analyzer.__init__(self);
       
        if len(lattice_vectors) == 0:
                globals.msg.error("analyze.sq: List of supplied latice vectors is empty.\n")
                raise RuntimeEror('Error creating collective variable.')

        if len(lattice_vectors) != len(phases):
                globals.msg.error("analyze.sq: #phases is not equal to #lattice_vectors.\n")
                raise RuntimeEror('Error creating collective variable.')

        if type(mode) != type(dict()):
                globals.msg.error("analyze.sq: Mode amplitudes specified incorrectly.\n")
                raise RuntimeEror('Error creating collective variable.')

        cpp_mode = hoomd.std_vector_scalar()
        for i in range(0, globals.system_definition.getParticleData().getNTypes()):
            t = globals.system_definition.getParticleData().getNameByType(i)

            if t not in mode.keys():
                globals.msg.error("cv.lamellar: Missing mode amplitude for particle type " + t + ".\n")
                raise RuntimeEror('Error creating collective variable.')
            cpp_mode.append(mode[t])

        cpp_lattice_vectors = _CollectiveVariable_plugin.std_vector_int3()
        for l in lattice_vectors:
            if len(l) != 3:
                globals.msg.error("cv.lamellar: List of input lattice vectors not a list of triples.\n")
                raise RuntimeError('Error creating collective variable.')
            cpp_lattice_vectors.append(hoomd.make_int3(l[0], l[1], l[2]))

        cpp_phases = _CollectiveVariable_plugin.std_vector_scalar()
        for l in phases:
            cpp_phases.append(l)

        cpp_grid = _CollectiveVariable_plugin.std_vector_uint()
        for l in grid:
            cpp_grid.append(l)

        # initialize the reflected c++ class
        if not globals.exec_conf.isCUDAEnabled():
            self.cpp_analyzer = _CollectiveVariable_plugin.CollectiveVariable(globals.system_definition, cpp_mode, cpp_lattice_vectors, cpp_phases, cpp_grid, endtime, filename, overwrite);
        else:
            self.cpp_analyzer = _CollectiveVariable_plugin.CollectiveVariableGPU(globals.system_definition, cpp_mode, cpp_lattice_vectors, cpp_phases, cpp_grid, endtime,filename, overwrite);

        self.setupAnalyzer(period)
Esempio n. 10
0
    def __init__(self, qstar, mode, nx, ny=None, nz=None, name=None,sigma=1.0,zero_modes=None):
        util.print_status_line()

        if name is not None:
            name = "_" + name
            suffix = name
        else:
            suffix = "" 

        if ny is None:
            ny = nx

        if nz is None:
            nz = nx

        _collective_variable.__init__(self, sigma, name)

        if type(mode) != type(dict()):
                globals.msg.error("cv.mesh: Mode amplitudes specified incorrectly.\n")
                raise RuntimeEror('Error creating collective variable.')

        cpp_mode = hoomd.std_vector_scalar()
        for i in range(0, globals.system_definition.getParticleData().getNTypes()):
            t = globals.system_definition.getParticleData().getNameByType(i)

            if t not in mode.keys():
                globals.msg.error("cv.mesh: Missing mode amplitude for particle type " + t + ".\n")
                raise RuntimeEror('Error creating collective variable.')
            cpp_mode.append(mode[t])

        cpp_zero_modes = _metadynamics.std_vector_int3()
        if zero_modes is not None:
            for l in zero_modes:
                if len(l) != 3:
                    globals.msg.error("cv.lamellar: List of modes to zero not a list of triples.\n")
                    raise RuntimeError('Error creating collective variable.')
                cpp_zero_modes.append(hoomd.make_int3(l[0], l[1], l[2]))

        if not globals.exec_conf.isCUDAEnabled():
            self.cpp_force = _metadynamics.OrderParameterMesh(globals.system_definition, nx,ny,nz,qstar, cpp_mode, cpp_zero_modes)
        else:
            self.cpp_force = _metadynamics.OrderParameterMeshGPU(globals.system_definition, nx,ny,nz,qstar, cpp_mode, cpp_zero_modes)

        globals.system.addCompute(self.cpp_force, self.force_name)
Esempio n. 11
0
    def __init__(self, mode, lattice_vectors, name=None,sigma=1.0,offs=0.0):
        util.print_status_line()

        if name is not None:
            name = "_" + name
            suffix = name
        else:
            suffix = "" 

        _collective_variable.__init__(self, sigma, name)

        if len(lattice_vectors) == 0:
                globals.msg.error("cv.lamellar: List of supplied latice vectors is empty.\n")
                raise RuntimeEror('Error creating collective variable.')
     
        if type(mode) != type(dict()):
                globals.msg.error("cv.lamellar: Mode amplitudes specified incorrectly.\n")
                raise RuntimeEror('Error creating collective variable.')

        cpp_mode = hoomd.std_vector_scalar()
        for i in range(0, globals.system_definition.getParticleData().getNTypes()):
            t = globals.system_definition.getParticleData().getNameByType(i)

            if t not in mode.keys():
                globals.msg.error("cv.lamellar: Missing mode amplitude for particle type " + t + ".\n")
                raise RuntimeEror('Error creating collective variable.')
            cpp_mode.append(mode[t])

        cpp_lattice_vectors = _metadynamics.std_vector_int3()
        for l in lattice_vectors:
            if len(l) != 3:
                globals.msg.error("cv.lamellar: List of input lattice vectors not a list of triples.\n")
                raise RuntimeError('Error creating collective variable.')
            cpp_lattice_vectors.append(hoomd.make_int3(l[0], l[1], l[2]))

        if not globals.exec_conf.isCUDAEnabled():
            self.cpp_force = _metadynamics.LamellarOrderParameter(globals.system_definition, cpp_mode, cpp_lattice_vectors, offs,suffix)
        else:
            self.cpp_force = _metadynamics.LamellarOrderParameterGPU(globals.system_definition, cpp_mode, cpp_lattice_vectors, offs, suffix)

        globals.system.addCompute(self.cpp_force, self.force_name)
Esempio n. 12
0
    def __init__(self, filename_sq, filename_vh, mode, lattice_vectors, period=1, vanhove_endtime=1, overwrite=False):
        util.print_status_line();
    
        # initialize base class
        _analyzer.__init__(self);
       
        if len(lattice_vectors) == 0:
                globals.msg.error("analyze.sq: List of supplied latice vectors is empty.\n")
                raise RuntimeEror('Error creating collective variable.')

        if type(mode) != type(dict()):
                globals.msg.error("analyze.sq: Mode amplitudes specified incorrectly.\n")
                raise RuntimeEror('Error creating collective variable.')

        cpp_mode = hoomd.std_vector_scalar()
        for i in range(0, globals.system_definition.getParticleData().getNTypes()):
            t = globals.system_definition.getParticleData().getNameByType(i)

            if t not in mode.keys():
                globals.msg.error("cv.lamellar: Missing mode amplitude for particle type " + t + ".\n")
                raise RuntimeEror('Error creating collective variable.')
            cpp_mode.append(mode[t])

        cpp_lattice_vectors = _sq_plugin.std_vector_int3()
        for l in lattice_vectors:
            if len(l) != 3:
                globals.msg.error("cv.lamellar: List of input lattice vectors not a list of triples.\n")
                raise RuntimeError('Error creating collective variable.')
            cpp_lattice_vectors.append(hoomd.make_int3(l[0], l[1], l[2]))

        # initialize the reflected c++ class
        if not globals.exec_conf.isCUDAEnabled():
            self.cpp_analyzer = _sq_plugin.StructureFactor(globals.system_definition, cpp_mode, cpp_lattice_vectors, vanhove_endtime, filename_sq, filename_vh, overwrite);
        else:
            self.cpp_analyzer = _sq_plugin.StructureFactorGPU(globals.system_definition, cpp_mode, cpp_lattice_vectors, vanhove_endtime, filename_sq, filename_vh, overwrite);

        self.setupAnalyzer(period)
Esempio n. 13
0
    def __init__(self,
                 qstar,
                 mode,
                 nx,
                 ny=None,
                 nz=None,
                 name=None,
                 sigma=1.0,
                 zero_modes=None):
        util.print_status_line()

        if name is not None:
            name = "_" + name
            suffix = name
        else:
            suffix = ""

        if ny is None:
            ny = nx

        if nz is None:
            nz = nx

        _collective_variable.__init__(self, sigma, name)

        if type(mode) != type(dict()):
            globals.msg.error(
                "cv.mesh: Mode amplitudes specified incorrectly.\n")
            raise RuntimeEror('Error creating collective variable.')

        cpp_mode = hoomd.std_vector_scalar()
        for i in range(
                0,
                globals.system_definition.getParticleData().getNTypes()):
            t = globals.system_definition.getParticleData().getNameByType(i)

            if t not in mode.keys():
                globals.msg.error(
                    "cv.mesh: Missing mode amplitude for particle type " + t +
                    ".\n")
                raise RuntimeEror('Error creating collective variable.')
            cpp_mode.append(mode[t])

        cpp_zero_modes = _metadynamics.std_vector_int3()
        if zero_modes is not None:
            for l in zero_modes:
                if len(l) != 3:
                    globals.msg.error(
                        "cv.lamellar: List of modes to zero not a list of triples.\n"
                    )
                    raise RuntimeError('Error creating collective variable.')
                cpp_zero_modes.append(hoomd.make_int3(l[0], l[1], l[2]))

        if not globals.exec_conf.isCUDAEnabled():
            self.cpp_force = _metadynamics.OrderParameterMesh(
                globals.system_definition, nx, ny, nz, qstar, cpp_mode,
                cpp_zero_modes)
        else:
            self.cpp_force = _metadynamics.OrderParameterMeshGPU(
                globals.system_definition, nx, ny, nz, qstar, cpp_mode,
                cpp_zero_modes)

        globals.system.addCompute(self.cpp_force, self.force_name)
Esempio n. 14
0
    def _make_cpp_decomposition(self, box):
        # if the box is uniform in all directions, just use these values
        if self.uniform_x and self.uniform_y and self.uniform_z:
            self.cpp_dd = hoomd.DomainDecomposition(
                globals.exec_conf, box.getL(), self.nx, self.ny, self.nz,
                not globals.options.onelevel)
            return self.cpp_dd

        # otherwise, make the fractional decomposition
        try:
            fxs = hoomd.std_vector_scalar()
            fys = hoomd.std_vector_scalar()
            fzs = hoomd.std_vector_scalar()

            # if uniform, correct the fractions to be uniform as well
            if self.uniform_x and self.nx > 0:
                self.x = [1.0 / self.nx] * (self.nx - 1)
            if self.uniform_y and self.ny > 0:
                self.y = [1.0 / self.ny] * (self.ny - 1)
            if self.uniform_z and self.nz > 0:
                self.z = [1.0 / self.nz] * (self.nz - 1)

            sum_x = sum_y = sum_z = 0.0
            tol = 1.0e-5
            for i in self.x:
                if i <= -tol or i >= 1.0 - tol:
                    globals.msg.error(
                        "comm.decomposition: fraction must be between 0.0 and 1.0\n"
                    )
                    raise RuntimeError(
                        "Fractional decomposition must be between 0.0 and 1.0")
                fxs.append(i)
                sum_x += i
            if sum_x >= 1.0 - tol or sum_x <= -tol:
                globals.msg.error(
                    "comm.decomposition: fraction must be between 0.0 and 1.0\n"
                )
                raise RuntimeError(
                    "Sum of decomposition in x must lie between 0.0 and 1.0")

            for i in self.y:
                if i <= -tol or i >= 1.0 - tol:
                    globals.msg.error(
                        "comm.decomposition: fraction must be between 0.0 and 1.0\n"
                    )
                    raise RuntimeError(
                        "Fractional decomposition must be between 0.0 and 1.0")
                fys.append(i)
                sum_y += i
            if sum_y >= 1.0 - tol or sum_y <= -tol:
                globals.msg.error(
                    "comm.decomposition: fraction must be between 0.0 and 1.0\n"
                )
                raise RuntimeError(
                    "Sum of decomposition in y must lie between 0.0 and 1.0")

            for i in self.z:
                if i <= -tol or i >= 1.0 - tol:
                    globals.msg.error(
                        "comm.decomposition: fraction must be between 0.0 and 1.0\n"
                    )
                    raise RuntimeError(
                        "Fractional decomposition must be between 0.0 and 1.0")
                fzs.append(i)
                sum_z += i
            if sum_z >= 1.0 - tol or sum_z <= -tol:
                globals.msg.error(
                    "comm.decomposition: fraction must be between 0.0 and 1.0\n"
                )
                raise RuntimeError(
                    "Sum of decomposition in z must lie between 0.0 and 1.0")

            self.cpp_dd = hoomd.DomainDecomposition(globals.exec_conf,
                                                    box.getL(), fxs, fys, fzs)
            return self.cpp_dd

        except TypeError as te:
            globals.msg.error(
                "Fractional cuts must be iterable (list, tuple, etc.)\n")
            raise te