Ejemplo n.º 1
0
 def append(self, file, align_codes='all', atom_files=None, remove_gaps=True,
            alignment_format='PIR', io=None, allow_alternates=False):
     """Add sequence(s) from an alignment file"""
     if io is None:
         io = self.env.io
     new_align_codes = align_codes
     new_atom_files = atom_files
     align_codes = [seq.code for seq in self]
     atom_files = [seq.atom_file for seq in self]
     if new_align_codes is not None:
         if modutil.non_string_iterable(new_align_codes):
             align_codes.extend(new_align_codes)
         else:
             align_codes.append(new_align_codes)
     if new_atom_files is not None:
         fmt = alignment_format.upper()
         if fmt != 'PAP' and fmt != 'INSIGHT':
             raise TypeError("atom_files is only used for PAP and " + \
                             "INSIGHT alignment files")
         if modutil.non_string_iterable(new_atom_files):
             atom_files.extend(new_atom_files)
         else:
             atom_files.append(new_atom_files)
     fh = modfile._get_filehandle(file, 'r')
     func = _modeller.mod_alignment_read
     return func(self.modpt, io.modpt, self.env.libs.modpt, align_codes,
                 atom_files, fh.file_pointer, remove_gaps, alignment_format,
                 allow_alternates)
Ejemplo n.º 2
0
    def only_atom_types(self, atom_types):
        """Create and return a new selection, containing only atoms from
           the current selection of the given type(s).

           :param str atom_types: A space-separated list of type(s)
                  (e.g. 'CA CB').
           :return: A new selection containing only atoms of the given type(s).
           :rtype: :class:`selection`"""
        if modutil.non_string_iterable(atom_types):
            atom_types = " ".join(atom_types)
        return self.__filter(_modeller.mod_selection_atom_types, atom_types)
Ejemplo n.º 3
0
 def patch(self, residue_type, residues):
     """Patch the model topology"""
     if not modutil.non_string_iterable(residues):
         residues = [residues]
     for r in residues:
         if not isinstance(r, coordinates.Residue) or r.mdl is not self:
             raise TypeError("expecting one or more 'Residue' objects")
     return _modeller.mod_model_patch(mdl=self.modpt,
                                      libs=self.env.libs.modpt,
                                      residue_type=residue_type,
                                      residue_ids=[r.index \
                                                   for r in residues])
Ejemplo n.º 4
0
    def only_residue_types(self, residue_types):
        """Create and return a new selection, containing only atoms from
           the current selection in residues of the given type(s).

           :param str residue_types: A space-separated list of type(s)
                  (e.g. 'ALA ASP').
           :return: A new selection containing only atoms in residues
                  of the given type(s).
           :rtype: :class:`selection`"""
        if modutil.non_string_iterable(residue_types):
            residue_types = " ".join(residue_types)
        libs = self.__get_libs()
        return self.__filter(_modeller.mod_selection_residue_types,
                             residue_types, libs)
Ejemplo n.º 5
0
 def _parse_values(self, values, modal, param, idim):
     if len(modal) <= idim:
         modal.append(len(values))
     else:
         if modal[idim] != len(values):
             raise ValueError("Spline parameters should be a " +
                              "rectangular matrix")
     for elmnt in values:
         if modutil.non_string_iterable(elmnt):
             self._parse_values(elmnt, modal, param, idim + 1)
         else:
             if idim + 1 != len(modal):
                 raise ValueError("Spline parameters should be a " +
                                  "rectangular matrix")
             param.append(elmnt)
Ejemplo n.º 6
0
 def __get_list_atom_indices(self, atoms):
     inds = []
     mdl = None
     for obj in atoms:
         if modutil.non_string_iterable(obj) \
            and not hasattr(obj, 'get_atom_indices'):
             (objinds, objmdl) = self.__get_list_atom_indices(obj)
         else:
             (objinds, objmdl) = obj.get_atom_indices()
         if mdl is None:
             mdl = objmdl
         elif mdl != objmdl:
             raise ValueError("All atoms must be from the same model")
         inds.extend(objinds)
     return (inds, mdl)
Ejemplo n.º 7
0
 def remove(self, obj):
     """Removes an object (e.g. atom, residue) from the selection;
        raises KeyError if not present"""
     if not hasattr(obj, "get_atom_indices") \
        and modutil.non_string_iterable(obj):
         for x in obj:
             self.remove(x)
     else:
         if obj not in self:
             raise KeyError(obj)
         (inds, mdl) = obj.get_atom_indices()
         if self.__mdl is not mdl:
             raise ValueError("All atoms must be in the same model!")
         for ind in inds:
             del self.__selection[ind]
Ejemplo n.º 8
0
 def add(self, obj):
     """Adds a new object (e.g. atom, residue) to the selection"""
     if not hasattr(obj, "get_atom_indices") \
        and modutil.non_string_iterable(obj):
         for x in obj:
             self.add(x)
     else:
         self.__check_object(obj)
         (inds, mdl) = obj.get_atom_indices()
         if self.__mdl is None:
             self.__mdl = mdl
         elif self.__mdl is not mdl:
             raise ValueError("All atoms must be in the same model!")
         for ind in inds:
             self.__selection[ind] = None