Ejemplo n.º 1
0
def add_new_elements(cgmodel):
    """
        Add coarse grained particle types to OpenMM.

        :param cgmodel: CGModel object (contains all attributes for a coarse grained model).
        :type cgmodel: class

        :returns: 
           - particle_list (list) - a list of the particles that were added to OpenMM's 'Element' List.

        :Example:

        >>> from foldamers.cg_model.cgmodel import CGModel
        >>> cgmodel = CGModel()
        >>> particle_types = add_new_elements(cgmodel)

        .. warning:: If the particle names were user defined, and any of the names conflict with existing element names in OpenMM, OpenMM will issue an error exit.

        """
    element_index = 117
    cg_particle_index = 1
    particle_list = []

    for monomer_type in cgmodel.monomer_types:
        for backbone_bead in range(monomer_type['backbone_length']):
            particle_name = str("X" + str(cg_particle_index))
            particle_symbol = str("X" + str(cg_particle_index))
            if particle_symbol not in elem.Element._elements_by_symbol:
                mass = cgmodel.get_particle_mass(cg_particle_index - 1)
                elem.Element(element_index, particle_name, particle_symbol,
                             mass)
                particle_list.append(particle_symbol)
                element_index = element_index + 1
            cg_particle_index = cg_particle_index + 1
            if type(monomer_type['sidechain_positions']) == int:
                sidechain_positions = [monomer_type['sidechain_positions']]
            else:
                sidechain_positions = monomer_type['sidechain_positions']
            if backbone_bead in sidechain_positions:
                for sidechain in range(monomer_type['sidechain_length']):
                    particle_name = str("A" + str(cg_particle_index))
                    particle_symbol = str("A" + str(cg_particle_index))
                    if particle_symbol not in elem.Element._elements_by_symbol:
                        mass = cgmodel.get_particle_mass(cg_particle_index - 1)
                        elem.Element(element_index, particle_name,
                                     particle_symbol, mass)
                        particle_list.append(particle_symbol)
                        element_index = element_index + 1
                    cg_particle_index = cg_particle_index + 1
    return (particle_list)
Ejemplo n.º 2
0
def add_new_elements(cgmodel):
    """
    Add coarse grained particle types to OpenMM.

    :param cgmodel: CGModel object (contains all attributes for a coarse grained model).
    :type cgmodel: class

    :returns:
       - new_particles (list) - a list of the particle names that were added to OpenMM's 'Element' List.

    :Example:

    >>> from foldamers.cg_model.cgmodel import CGModel
    >>> cgmodel = CGModel()
    >>> particle_types = add_new_elements(cgmodel)

    .. warning:: If the particle names were user defined, and any of the names conflict with existing element names in OpenMM, OpenMM will issue an error exit.

    """
    element_index = 117
    new_particles = []

    for particle in cgmodel.particle_list:
        particle_name = particle["name"]
        if particle_name.upper() not in elem.Element._elements_by_symbol:
            elem.Element(element_index, particle_name, particle_name,
                         cgmodel.get_particle_mass(particle))
            element_index = element_index + 1
            new_particles.append(particle_name)

    return new_particles
Ejemplo n.º 3
0
 def _create_element(self, element, mass):
     if not isinstance(element, elem.Element):
         try:
             element = elem.get_by_symbol(element)
         except KeyError:
             # Enables support for non-atomistic "element types"
             if element not in self.non_element_types:
                 warnings.warn('Non-atomistic element type detected. '
                               'Creating custom element for {}'.format(element))
             element = elem.Element(number=0,
                                    mass=mass,
                                    name=element,
                                    symbol=element)
     return element
Ejemplo n.º 4
0
    def registerAtomType(self, parameters):
        """Register a new atom type. """
        name = parameters['name']
        if name in self._atomTypes:
            raise ValueError('Found multiple definitions for atom type: ' +
                             name)
        atomClass = parameters['class']
        mass = _convertParameterToNumber(parameters['mass'])
        element = None
        if 'element' in parameters:
            element = parameters['element']
            if not isinstance(element, elem.Element):
                try:
                    element = elem.get_by_symbol(element)
                except KeyError:
                    # Enables support for non-atomistic "element types"
                    if element not in self.non_element_types:
                        warnings.warn(
                            'Non-atomistic element type detected. '
                            'Creating custom element for {}'.format(element))
                    element = elem.Element(number=0,
                                           mass=parameters['mass'],
                                           name=element,
                                           symbol=element)
                    self.non_element_types[element.name] = element

        self._atomTypes[name] = self.__class__._AtomType(
            name, atomClass, mass, element)
        if atomClass in self._atomClasses:
            typeSet = self._atomClasses[atomClass]
        else:
            typeSet = set()
            self._atomClasses[atomClass] = typeSet
        typeSet.add(name)
        self._atomClasses[''].add(name)

        name = parameters['name']
        if 'def' in parameters:
            self._atomTypeDefinitions[name] = parameters['def']
        if 'overrides' in parameters:
            overrides = set(parameters['overrides'].split(","))
            if overrides:
                self._atomTypeOverrides[name] = overrides
        if 'des' in parameters:
            self._atomTypeDesc[name] = parameters['desc']