def __initialize_variables__(self):
     self.weights = np.array(get_records_database_property_values(self.targetAtomsIndexes, self.structure, self.weighting))
     elements = self._trajectory.elements
     self.elements = [elements[idx] for idx in self.targetAtomsIndexes]
     elementsSet = set(self.elements)
     self.elementsWeights = dict(zip(elementsSet,[get_element_property(el, self.weighting) for el in elementsSet]))
     self.elementsNumber = dict(Counter(self.elements))
 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
 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)
 def __initialize_variables__(self, axis):
     self.weights = np.array(get_records_database_property_values(self.targetAtomsIndexes, self.structure, self.weighting))
     elements = self._trajectory.elements
     self.elements = [elements[idx] for idx in self.targetAtomsIndexes]
     elementsSet = set(self.elements)
     self.elementsWeights = dict(zip(elementsSet,[get_element_property(el, self.weighting) for el in elementsSet]))
     self.elementsNumber = dict(Counter(self.elements))
     # check atoms indexes
     assert not len(set.intersection(set(self.cylinderAtomsIndexes), set(self.targetAtomsIndexes))), Logger.error("cylinderAtomsIndexes and targetAtomsIndexes can't have any index in common")
     # set axis
     if axis is None:
         axis = {"principal":self.cylinderAtomsIndexes}
     self.axis = AxisDefinition(self._trajectory, axis)
Example #5
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 list(center.keys()) in (["fixed"], ["selection"]), Logger.error("center can have one of two keys '%s'" %(["fixed", "selection"]))
        key = list(center.keys())[0]
        value = list(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}