Beispiel #1
0
 def __NAMD_PSF_export_atoms__(self, fd, indexesOffset=1):
     # write the title line with the number of bonds
     fd.write("\n%8d !NATOM\n" % len(self.__pdb))
     # get indexes
     indexes = self.__pdb.indexes
     # get atoms weights
     atomsWeights = np.array(
         get_records_database_property_values(indexes, self.__pdb,
                                              "atomicWeight"))
     # start writing bonds
     for idx in indexes:
         at = self.__pdb[idx]
         atomLine = str("%i" % (idx + indexesOffset)).rjust(8, " ")
         atomLine += str(" ")  # empty space
         atomLine += str("%s" % at["segment_identifier"]).ljust(4, " ")
         atomLine += str(" ")  # empty space
         atomLine += str("%i" % at["sequence_number"]).ljust(5, " ")
         atomLine += str("%s" % at["residue_name"]).ljust(5, " ")
         atomLine += str("%s" % at["atom_name"]).ljust(5, " ")  # atome name
         atomLine += str("%s" % at["atom_name"]).ljust(
             5, " ")  # force field type
         atomLine += str("  0.000000")  # charge
         atomLine += str("      ")  # empty space
         atomLine += str("%8.4f" % atomsWeights[idx])
         atomLine += str("           0")
         atomLine += str("\n")
         fd.write(atomLine)
 def __initialize_variables__(self, makeContiguous, atomsRadius,
                              probeRadius, resolution, storeSurfacePoints,
                              tempdir):
     assert isinstance(makeContiguous,
                       bool), 'makeContiguous must be boolean'
     self.__makeContiguous = makeContiguous
     # check probeRadius
     assert is_number(probeRadius), "probeRadius must be a number"
     probeRadius = float(probeRadius)
     assert probeRadius >= 0, 'probeRadius must be bigger or equal to 0'
     # check atomsRadius
     if isinstance(atomsRadius, str):
         atomsRadius = get_records_database_property_values(
             indexes=self.targetAtomsIndexes,
             pdb=self.structure,
             property=atomsRadius)
     assert len(atomsRadius) == len(
         self.targetAtomsIndexes
     ), 'atomsRadius must have the same number of input as target atoms'
     assert all([is_number(v)
                 for v in atomsRadius]), 'all atomsRadius must be numbers'
     atomsRadius = [float(v) for v in atomsRadius]
     assert all([v > 0 for v in atomsRadius]), 'all atomsRadius must be >0'
     # set atoms radius
     self.__atomsRadius = np.array(atomsRadius).astype(float) + probeRadius
     # set atoms data
     self.__atomsData = _AtomsData(tempdir=tempdir)
     # check probeRadius
     assert is_number(resolution), "resolution must be a number"
     resolution = float(resolution)
     assert resolution > 0, 'resolution must be > 0'
     self.__resolution = resolution
     assert isinstance(storeSurfacePoints,
                       bool), 'storeSurfacePoints must be boolean'
     self.__storeSurfacePoints = storeSurfacePoints
 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))
Beispiel #4
0
 def __initialize_variables__(self):
     # calculate weights
     self.weights = np.array(
         get_records_database_property_values(self.globalMotionAtomsIndexes,
                                              self.structure,
                                              "atomicWeight"))
     self.totalWeight = np.sum(self.weights)
 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)
Beispiel #6
0
 def __initialize_variables__(self):
     self.weights = np.array(get_records_database_property_values(self.targetAtomsIndexes, self.structure, "atomicWeight"))
     self.totalWeight = np.sum(self.weights)
     elements = self._trajectory.elements
     self.elements = [elements[idx] for idx in self.targetAtomsIndexes]
Beispiel #7
0
    def calculate_bonds(self,
                        regressive=False,
                        bondingRadii=None,
                        tolerance=0.25,
                        maxNumberOfBonds=4):
        """
        calculate the bonds list of all the atoms.\n

        :Parameters:
            #. regressive (boolean): If regressive all bonds are counted even those of earlier atoms.
            #. bondingRadii (numpy.array): The distances defining a bond. Must have the same length as indexes.
            #. tolerance (float): The tolerance is defined as the bond maximum stretching
            #. maxNumberOfBonds (integer): Maximum number of bonds allowed per atom
        """
        assert isinstance(regressive,
                          bool), Logger.error("regressive must be boolean")
        assert is_integer(maxNumberOfBonds), Logger.error(
            "maxNumberOfBonds must be integer")
        maxNumberOfBonds = int(float(maxNumberOfBonds))
        assert maxNumberOfBonds > 0, Logger.error(
            "maxNumberOfBonds must be bugger than 0")
        # get indexes
        indexes = self.__pdb.indexes
        # get bond radii
        if bondingRadii is None:
            bondingRadii = np.array(
                get_records_database_property_values(indexes, self.__pdb,
                                                     "covalentRadius"))
        # get coordinates
        coordinates = get_coordinates(indexes, self.__pdb)
        # initialize bonds
        self._bonds = []
        if regressive:
            indexes = range(coordinates.shape[0])
        else:
            indexes = range(coordinates.shape[0] - 1)
        bc = self.__pdb.boundaryConditions
        for idx in indexes:
            if regressive:
                cRadii = 0.5 * (bondingRadii + bondingRadii[idx]) + tolerance
                distances = bc.real_distance(coordinates[idx], coordinates)
                # find where distance < cRadii
                connected = list(np.where(distances <= cRadii)[0])
                # remove self atom
                connected.remove(idx)
            else:
                cRadii = 0.5 * (bondingRadii[idx + 1:] +
                                bondingRadii[idx]) + tolerance
                distances = bc.real_distance(coordinates[idx],
                                             coordinates[idx + 1:])
                # find where distance < cRadii
                connected = list(np.where(distances <= cRadii)[0] + idx + 1)
            assert len(connected) <= maxNumberOfBonds, Logger.error(
                "record '%s' is found having more than %i bonds with %s " %
                (str(idx), maxNumberOfBonds, str(connected)))
            # set values to connectivity array
            self._bonds.append(connected)
            # increment number of bonds
            self._numberOfBonds += len(connected)
        # add last atom bonds as empty list
        if not regressive:
            self._bonds.append([])