예제 #1
0
    def get_center_definition(self, center):
        """
        check and return axis definition.\n
 
        :Parameters:
            #. center (dictionary): The center definition    
        
        :returns:
            #. center (dictionary): The verified center definition     
        """
        assert isinstance(center,
                          dict), Logger.error("center must be a dictionary")
        assert center.keys() in (["fixed"], ["selection"]), Logger.error(
            "center can have one of two keys '%s'" % (["fixed", "selection"]))
        key = center.keys()[0]
        value = center.values()[0]
        # fixed center
        if key == "fixed":
            assert isinstance(
                value, (list, tuple, set, numpy.array)), Logger.error(
                    "fixed center value must be a list of three floats")
            value = list(value)
            assert len(value) == 3, Logger.error(
                "fixed center value must be a list of three floats")
            try:
                value = np.array([float(val) for val in value])
            except:
                raise Logger.error(
                    "fixed center value must be a list of three floats")
        # selection center
        elif key == "selection":
            assert isinstance(
                value,
                dict), Logger.error("selection value must be a dictionary")
            assert sorted(value.keys()) == (sorted([
                "indexes", "weighting"
            ])), Logger.error(
                "center selection value dictionary must have two keys '%s'" %
                (["indexes", "weighting"]))
            indexes = get_atoms_indexes(self.trajectory, value["indexes"])
            weighting = value["weighting"]
            assert is_element_property(weighting), Logger.error(
                "weighting '%s' don't exist in database" % weighting)
            elements = self.trajectory.elements
            weights = np.array([
                get_element_property(elements[idx], weighting)
                for idx in indexes
            ])
            value = {
                "indexes": indexes,
                "weighting": weighting,
                "weights": weights
            }
        else:
            raise Logger.error("center definition not valid")
        return {key: value}
 def set_weighting(self, weighting):
     """
     Sets elements weighting. It must a valid entry of pdbParser atoms database
     
     :Parameters:
         #. weighting (string): The elements weighting.
     """
     assert is_element_property(weighting),LOGGER.error( "weighting is not a valid pdbParser atoms database entry")
     assert weighting != "atomicFormFactor", LOGGER.error("atomicFormFactor weighting is not allowed")
     self.__weighting = weighting
예제 #3
0
 def __init__(self,
              trajectory,
              configurationsIndexes,
              cylinderAtomsIndexes,
              targetAtomsIndexes,
              axis=None,
              weighting="equal",
              histBin=1,
              *args,
              **kwargs):
     # set trajectory
     super(MeanSquareDisplacementInCylinder,
           self).__init__(trajectory, *args, **kwargs)
     # set configurations indexes
     self.configurationsIndexes = self.get_trajectory_indexes(
         configurationsIndexes)
     # set atoms indexes
     self.targetAtomsIndexes = self.get_atoms_indexes(targetAtomsIndexes)
     self.cylinderAtomsIndexes = self.get_atoms_indexes(
         cylinderAtomsIndexes)
     # set steps indexes
     self.numberOfSteps = len(self.targetAtomsIndexes)
     # set weighting
     assert is_element_property(weighting), Logger.error(
         "weighting '%s' don't exist in database" % weighting)
     self.weighting = weighting
     # set residency time histogram bin
     try:
         self.histBin = float(histBin)
     except:
         raise Logger.error(
             "histBin must be number convertible. %s is given." % histBin)
     assert self.histBin % 1 == 0, logger.error(
         "histBin must be integer. %s is given." % histBin)
     assert self.histBin > 0, logger.error(
         "histBin must be positive. %s is given." % histBin)
     assert self.histBin < len(self.configurationsIndexes), logger.error(
         "histBin must smaller than numberOfConfigurations")
     # initialize variables
     self.__initialize_variables__(axis)
     # initialize results
     self.__initialize_results__()
     # get cylinder centers, matrices, radii, length
     Logger.info(
         "%s --> initializing cylinder parameters along all configurations"
         % self.__class__.__name__)
     self.cylCenters, self.cylMatrices, self.cylRadii, self.cylLengths = self.__get_cylinder_properties__(
     )
예제 #4
0
 def __initialize_variables__(self, weighting, axis, radii, length):
     # get elements
     elements = self._trajectory.elements
     self.elements = [elements[idx] for idx in self.targetAtomsIndexes]
     self.elementsSet = list(set(self.elements))
     # set weighting
     assert is_element_property(weighting), Logger.error(
         "weighting '%s' don't exist in database" % weighting)
     self.weighting = weighting
     self.weights = np.array(
         [get_element_property(el, self.weighting) for el in self.elements])
     self.elementsWeights = dict(
         zip(self.elementsSet, [
             get_element_property(el, self.weighting)
             for el in self.elementsSet
         ]))
     self.elementsNumber = dict(Counter(self.elements))
     # set axis
     self.axis = AxisDefinition(self._trajectory, axis)
     # set radii
     assert isinstance(
         radii,
         (list, tuple, set,
          np.ndarray)), Logger.error("radii must be a list or numpy.array")
     try:
         radii = np.array(sorted(set(radii)), dtype=np.float32)
     except:
         raise Logger.error("radii element must be numbers")
     assert len(
         radii.shape) == 1, Logger.error("radii must be uni-dimensional")
     assert radii[0] > 0, Logger.error("all radii array must be positive")
     self.radii = radii
     # set length
     try:
         length = float(length)
     except:
         raise Logger.error("length must be numbers")
     assert length > 0, Logger.error("length must be positive")
     self.length = length
     # cylinder volume
     self.cylinderVolume = self.length * np.pi * self.radii[-1]**2
     self.cylindersVolumes = 2 * np.pi * self.radii[0:-1] * (
         self.radii[1:] - self.radii[0:-1]) * self.length
     self.cumCylindersVolumes = np.pi * self.length * self.radii[1:]**2
예제 #5
0
 def __initialize_variables__(self, weighting, axis, radius, lengths):
     # get elements
     elements = self._trajectory.elements
     self.elements = [elements[idx] for idx in self.targetAtomsIndexes]
     self.elementsSet = list(set(self.elements))
     # set weighting
     assert is_element_property(weighting), Logger.error(
         "weighting '%s' don't exist in database" % weighting)
     self.weighting = weighting
     self.weights = np.array(
         [get_element_property(el, self.weighting) for el in self.elements])
     self.elementsWeights = dict(
         zip(self.elementsSet, [
             get_element_property(el, self.weighting)
             for el in self.elementsSet
         ]))
     self.elementsNumber = dict(Counter(self.elements))
     # set axis
     self.axis = AxisDefinition(self._trajectory, axis)
     # set length
     assert isinstance(lengths, (
         list, tuple, set,
         np.ndarray)), Logger.error("lengths must be a list or numpy.array")
     try:
         lengths = np.array(sorted(set(lengths)), dtype=np.float32)
     except:
         raise Logger.error("lengths element must be numbers")
     assert len(lengths.shape) == 1, Logger.error(
         "lengths must be uni-dimensional")
     self.lengths = lengths
     # set radius
     try:
         radius = float(radius)
     except:
         raise Logger.error("radius must be numbers")
     assert radius > 0, Logger.error("radius must be positive")
     self.radius = radius
     # cylinder volume
     self.cylinderVolume = (self.lengths[-1] -
                            self.lengths[0]) * np.pi * self.radius**2
     self.diskVolumes = (self.lengths[1:] -
                         self.lengths[0:-1]) * np.pi * self.radius**2
     self.cumDisksVolumes = np.cumsum(self.diskVolumes)
예제 #6
0
 def __init__(self,
              trajectory,
              configurationsIndexes,
              targetAtomsIndexes,
              weighting="equal",
              *args,
              **kwargs):
     # set trajectory
     super(MeanSquareDisplacement, self).__init__(trajectory, *args,
                                                  **kwargs)
     # set steps indexes
     self.targetAtomsIndexes = self.get_atoms_indexes(targetAtomsIndexes)
     self.numberOfSteps = len(self.targetAtomsIndexes)
     # set configurations indexes
     self.configurationsIndexes = self.get_trajectory_indexes(
         configurationsIndexes)
     # set weighting
     assert is_element_property(weighting), Logger.error(
         "weighting '%s' don't exist in database" % weighting)
     self.weighting = weighting
     # initialize variables
     self.__initialize_variables__()
     # initialize results
     self.__initialize_results__()