Exemplo n.º 1
0
 def _get_blr_to_jib(self):
     point_l = self.gantry.crane.bottom_left()
     point_r = self.gantry.crane.bottom_right()
     angle = self.jib.jib.angle
     # result = Point(0, 0), Point(-10000, -10000)
     result = None
     if angle > radians(0) and angle < radians(180):
         result1 = None
         result2 = None
         # remove code repetition
         if angle > radians(0) and angle < radians(90):
             raw_result = self._get_perpendicular_bottom_angle_to_jib(
                 point_r)
             if raw_result[1].x >= self.jib.jib.point_1.x and raw_result[
                     1].x <= self.jib.jib.get_two_point().x:
                 result1 = raw_result
             raw_result = self._get_perpendicular_bottom_angle_to_jib(
                 point_l)
             if raw_result[1].x >= self.jib.jib.point_1.x and raw_result[
                     1].x <= self.jib.jib.get_two_point().x:
                 result2 = raw_result
         else:
             raw_result = self._get_perpendicular_bottom_angle_to_jib(
                 point_r)
             if raw_result[1].x <= self.jib.jib.point_1.x and raw_result[
                     1].x >= self.jib.jib.get_two_point().x:
                 result1 = raw_result
             raw_result = self._get_perpendicular_bottom_angle_to_jib(
                 point_l)
             if raw_result[1].x <= self.jib.jib.point_1.x and raw_result[
                     1].x >= self.jib.jib.get_two_point().x:
                 result2 = raw_result
         if result1 and result2:
             result1_length = length(result1)
             result2_length = length(result2)
             if result1_length < result2_length:
                 result = result1
             else:
                 result = result2
         elif result1:
             result = result1
         elif result2:
             result = result2
     if self.debug:
         if result:
             self._update_render_for_line(self.line[0], result[0],
                                          result[1])
         else:
             self._update_render_for_line(self.line[0], Point(-1, -1),
                                          Point(-2, -2))
     return result
Exemplo n.º 2
0
 def _get_jib_to_angle_blr(self):
     point_bl = self.gantry.crane.bottom_left()
     point_br = self.gantry.crane.bottom_right()
     result = Point(0, 0), Point(-10000, -10000)
     result1 = self._get_length_jib_bottom_angle(point_bl)
     result2 = self._get_length_jib_bottom_angle(point_br)
     result1_length = length(result1)
     result2_length = length(result2)
     if result1_length < result2_length:
         result = result1
     else:
         result = result2
     if self.debug and result:
         self._update_render_for_line(self.line[6], result[0], result[1])
     return result
Exemplo n.º 3
0
    def decision_making(self):
        """
        Here all base logic. FIX
        """
        length_distances = []
        is_warnings = False

        blr_to_jib = self._get_blr_to_jib()
        if blr_to_jib:
            real_length = length(blr_to_jib)
            length_distances.append(real_length)
            is_include_warning = self._decision_for_blr_to_jib(real_length)
            if is_include_warning:
                is_warnings = True

        # analyse for vertical
        jib_to_lr = self._get_jib_to_left_right()
        if jib_to_lr:
            real_length = length(jib_to_lr)
            length_distances.append(real_length)
            is_include_warning = self._decision_for_jib_to_lr(real_length)
            if is_include_warning:
                is_warnings = True

        jib_to_b = self._get_jib_to_bottom()
        if jib_to_b:
            real_length = length(jib_to_b)
            length_distances.append(real_length)
            is_include_warning = self._decision_for_jib_to_b(real_length)
            if is_include_warning:
                is_warnings = True

        jib_to_angle_bl = self._get_jib_to_angle_blr()
        if jib_to_angle_bl:
            real_length = length(jib_to_angle_bl)
            length_distances.append(real_length)

        distance = min(length_distances)
        self.distance = int(round(distance, 0))

        if not is_warnings:
            self.desired_gantry_crane_block = 'None'
            self.desired_jib_crane_block = 'None'
            self.desired_jib_block = 'None'
            self.desired_gantry_danger = False
            self.desired_jib_danger = False
            self.desired_gantry_warning = False
            self.desired_jib_warning = False
Exemplo n.º 4
0
 def find_salt_bridges(self, cutoff=8.0):
     """Find all salt bridges in the protein
     """
     SBs = []
     self.get_titratable_groups()
     for res1 in self.titratable_groups.keys():
         r1_cens = self.calculate_titgroup_center(res1)
         for group1 in r1_cens[res1].keys():
             group1_ID = '%s:%s' % (res1, group1)
             for res2 in self.titratable_groups.keys():
                 r2_cens = self.calculate_titgroup_center(res2)
                 for group2 in r2_cens[res2].keys():
                     group2_ID = '%s:%s' % (res2, group2)
                     if group1_ID != group2_ID:
                         if self.titgroups[group1][
                                 'charge'] * self.titgroups[group2][
                                     'charge'] == -1:
                             import geometry
                             dist = geometry.length(r1_cens[res1][group1] -
                                                    r2_cens[res2][group2])
                             if dist <= cutoff:
                                 SBs.append([group1_ID, group2_ID, dist])
     #
     # Done
     #
     return SBs
Exemplo n.º 5
0
def calculate_burning_perimeter(regression_map, regression_depth, map_ratio,
                                fidelity):
    contours = measure.find_contours(regression_map,
                                     regression_depth,
                                     fully_connected='low')
    perimeter = 0
    for contour in contours:
        perimeter += (geometry.length(contour, fidelity)) * map_ratio
    return perimeter
Exemplo n.º 6
0
    def getCorePerimeter(self, regDist):
        mapDist = self.normalize(regDist)

        corePerimeter = 0
        contours = measure.find_contours(self.regressionMap,
                                         mapDist,
                                         fully_connected='low')
        for contour in contours:
            corePerimeter += self.mapToLength(
                geometry.length(contour, self.mapDim))

        return corePerimeter
Exemplo n.º 7
0
    def drawArrow(self, painter, p, v, head_size):
        base = p-v
        tip = p+v
        painter.drawLine(base, tip)

        vl = length(v)
        nv = v / vl
        head_size = head_size * vl

        orth = QPointF(nv.y(), -nv.x())*head_size
        base_center = tip-nv*head_size*2.0
        base1 = base_center + orth
        base2 = base_center - orth
        base_center = tip-nv*head_size*1.0

        painter.drawPolygon(QPolygonF([base_center, base1, tip, base2]))
Exemplo n.º 8
0
    def drawArrow(self, painter, p, v, head_size):
        base = p - v
        tip = p + v
        painter.drawLine(base, tip)

        vl = length(v)
        nv = v / vl
        head_size = head_size * vl

        orth = QPointF(nv.y(), -nv.x()) * head_size
        base_center = tip - nv * head_size * 2.0
        base1 = base_center + orth
        base2 = base_center - orth
        base_center = tip - nv * head_size * 1.0

        painter.drawPolygon(QPolygonF([base_center, base1, tip, base2]))
Exemplo n.º 9
0
    def __init__(self, result, result_type, forward=True):
        QObject.__init__(self)
        self.result = result
        self.result_type = result_type
        if result_type == "Data":
            self.data = result
            self.image_list = result.images_name
            if forward:
                self.images = result.images_name[:-1]
            else:
                self.images = result.images_name[1:]
            self.forward = forward
        else:
            self.data = result.data
            self.image_list = result.images_used
            self.images = result.images
            self.forward = (self.image_list[0] == self.images[0])


# Find maximum velocity
        image_list = self.image_list
        data = self.data
        max_v = 0
        for i, image_id in enumerate(image_list[:-1]):
            next_image_id = image_list[i + 1]
            d1 = data[image_id]
            d2 = data[next_image_id]
            dt = d2.time - d1.time
            for pt_id in d1:
                if pt_id in d2:
                    v = (d2[pt_id] - d1[pt_id]) / dt
                    vl = length(v)
                    if vl > max_v:
                        max_v = vl
        self.max_velocity = max_v
        self.factor = 0.5
        params = parameters.instance
        self.color = params.arrow_color
        self.head_size = params.arrow_head_size
        self.line_width = self.data.minScale() * params.arrow_line_size
Exemplo n.º 10
0
    def __init__(self, result, result_type, forward=True):
        QObject.__init__(self)
        self.result = result
        self.result_type = result_type
        if result_type == "Data":
            self.data = result
            self.image_list = result.images_name
            if forward:
                self.images = result.images_name[:-1]
            else:
                self.images = result.images_name[1:]
            self.forward = forward
        else:
            self.data = result.data
            self.image_list = result.images_used
            self.images = result.images
            self.forward = (self.image_list[0] == self.images[0])
# Find maximum velocity
        image_list = self.image_list
        data = self.data
        max_v = 0
        for i, image_id in enumerate(image_list[:-1]):
            next_image_id = image_list[i+1]
            d1 = data[image_id]
            d2 = data[next_image_id]
            dt = d2.time - d1.time
            for pt_id in d1:
                if pt_id in d2:
                    v = (d2[pt_id] - d1[pt_id]) / dt
                    vl = length(v)
                    if vl > max_v:
                        max_v = vl
        self.max_velocity = max_v
        self.factor = 0.5
        params = parameters.instance
        self.color = params.arrow_color
        self.head_size = params.arrow_head_size
        self.line_width = self.data.minScale()*params.arrow_line_size
Exemplo n.º 11
0
 def find_salt_bridges(self,cutoff=8.0):
     """Find all salt bridges in the protein
     """
     SBs=[]
     self.get_titratable_groups()
     for res1 in self.titratable_groups.keys():
         r1_cens=self.calculate_titgroup_center(res1)
         for group1 in r1_cens[res1].keys():
             group1_ID='%s:%s' %(res1,group1)
             for res2 in self.titratable_groups.keys():
                 r2_cens=self.calculate_titgroup_center(res2)
                 for group2 in r2_cens[res2].keys():
                     group2_ID='%s:%s' %(res2,group2)
                     if group1_ID!=group2_ID:
                         if self.titgroups[group1]['charge']*self.titgroups[group2]['charge']==-1:
                             import geometry
                             dist=geometry.length(r1_cens[res1][group1]-r2_cens[res2][group2])
                             if dist<=cutoff:
                                 SBs.append([group1_ID,group2_ID,dist])
     #
     # Done
     #
     return SBs
Exemplo n.º 12
0
 def __call__(self, painter, imageid):
     if imageid == len(self.images):
         return
     head_size = self.head_size
     color = self.color
     line_width = self.line_width
     max_velocity = self.max_velocity
     img1 = self.image_list[imageid]
     img2 = self.image_list[imageid + 1]
     d1 = self.data[img1]
     d2 = self.data[img2]
     dt = d2.time - d1.time
     pen = QPen(color)
     pen.setWidthF(line_width)
     brush = QBrush(color)
     painter.setPen(pen)
     painter.setBrush(brush)
     for pt_id in d1:
         if pt_id in d2:
             p = d1[pt_id] if self.forward else d2[pt_id]
             v = (d2[pt_id] - d1[pt_id]) / dt * self.factor
             vl = length(v)
             if abs(vl / max_velocity) > 1e-3:
                 self.drawArrow(painter, p, v, head_size)
Exemplo n.º 13
0
    def getRegressionData(self, mapDim, numContours=15, coreBlack=True):
        self.initGeometry(mapDim)
        self.generateCoreMap()

        masked = np.ma.MaskedArray(self.coreMap, self.mask)
        regressionMap = None
        contours = []
        contourLengths = {}

        try:
            self.generateRegressionMap()

            regmax = np.amax(self.regressionMap)

            regressionMap = self.regressionMap[:, :].copy()
            if coreBlack:
                regressionMap[np.where(
                    self.coreMap == 0)] = regmax  # Make the core black
            regressionMap = np.ma.MaskedArray(regressionMap, self.mask)

            for dist in np.linspace(0, regmax, numContours):
                contours.append([])
                contourLengths[dist] = 0
                layerContours = measure.find_contours(self.regressionMap,
                                                      dist,
                                                      fully_connected='low')
                for contour in layerContours:
                    contours[-1].append(geometry.clean(contour, self.mapDim,
                                                       3))
                    contourLengths[dist] += geometry.length(
                        contour, self.mapDim)

        except ValueError as exc:  # If there aren't any contours, do nothing
            print(exc)

        return (masked, regressionMap, contours, contourLengths)
Exemplo n.º 14
0
 def __call__(self, painter, imageid):
     if imageid == len(self.images):
         return
     head_size = self.head_size
     color = self.color
     line_width = self.line_width
     max_velocity = self.max_velocity
     img1 = self.image_list[imageid]
     img2 = self.image_list[imageid+1]
     d1 = self.data[img1]
     d2 = self.data[img2]
     dt = d2.time - d1.time
     pen = QPen(color)
     pen.setWidthF(line_width)
     brush = QBrush(color)
     painter.setPen(pen)
     painter.setBrush(brush)
     for pt_id in d1:
         if pt_id in d2:
             p = d1[pt_id] if self.forward else d2[pt_id]
             v = (d2[pt_id] - d1[pt_id]) / dt * self.factor
             vl = length(v)
             if abs(vl / max_velocity) > 1e-3:
                 self.drawArrow(painter, p, v, head_size)
Exemplo n.º 15
0
    def calculate_matrix(self,filename=None,eps=8,exdi=80,updater=None):
        """
        # This function calculates a simplified version of the charge-charge interaction
        # energy matrix
        #
        #
        # Calculate the factor that converts formal charges and distances in A into kT energies
        # eps is the dielectric constant
        """
        factor=(1.0/(4.0*pi*e0))*(e*e/A)*1.0/eps*1.0/(k*T)
        #
        # Get the fast scaled accessibility
        #
        acc=self.get_atoms_around(updater=updater)
        #
        # And now we calculate the matrix
        #
        import string
        if not getattr(self,'titratable_groups',None):
            self.get_titratable_groups()
        self.matrix={}
        self.distmatrix={}
        titgrps=self.titratable_groups
        residues=titgrps.keys()
        residues.sort()
        #
        # Get the total number of calcs
        #
        ncalcs=len(residues)*len(residues)
        count=0
        for residue in residues:
            for group in titgrps[residue]:
                name1=self.get_titgroup_name(residue,group) 
                if not self.matrix.has_key(name1):
                    self.matrix[name1]={}
                if not self.distmatrix.has_key(name1):
                    self.distmatrix[name1]={}
                #
                # Calculate distance from center of atoms
                #
                x=0.0
                y=0.0
                z=0.0
                for atom in group['atoms']:
                    x=x+self.atoms[residue+':'+atom]['X']/float(len(group['atoms']))
                    y=y+self.atoms[residue+':'+atom]['Y']/float(len(group['atoms']))
                    z=z+self.atoms[residue+':'+atom]['Z']/float(len(group['atoms']))
                #
                # Now for the second residue
                #
                for residue2 in titgrps.keys():
                    for group2 in titgrps[residue2]:
                        if not updater is None:
                            updater('%d of %d (%4.1f%% completed)' %(count,ncalcs,float(count)/float(ncalcs)*100.0))
                        count=count+1
                        name2=self.get_titgroup_name(residue2,group2)
                        if self.matrix[name1].has_key(name2):
                            continue
                        #
                        # Get center of atoms for this res
                        #
                        x2=0.0
                        y2=0.0
                        z2=0.0
                        for atom in group2['atoms']:
                            x2=x2+self.atoms[residue2+':'+atom]['X']/float(len(group2['atoms']))
                            y2=y2+self.atoms[residue2+':'+atom]['Y']/float(len(group2['atoms']))
                            z2=z2+self.atoms[residue2+':'+atom]['Z']/float(len(group2['atoms']))
                        #
                        # Get the distance
                        #
                        v1=numpy.array([x,y,z])
                        v2=numpy.array([x2,y2,z2])
                        import geometry
                        dist=geometry.length(v1-v2)
 
                        if dist!=0:
                            crg1=group['charge']
                            crg2=group2['charge']
                            ene=factor*float(crg1*crg2)/(math.pow(dist,1.5))
                            #
                            # Get the influence of the acc
                            #
                            acc_frac=math.sqrt(acc[name1]*acc[name2])
                            acc_frac=math.pow(acc_frac,2.0)
                            ene=ene*1.99*acc_frac+(1.0-acc_frac)*float(eps)/float(exdi)*ene
                        else:
                            ene=0.0
                        #if ene:
                        #    print '%20s - %20s: %7.3f' %(name1,name2,ene)
                        self.matrix[name1][name2]=[ene,0.0,0.0,0.0]
                        self.distmatrix[name1][name2]=dist 
                        if not self.matrix.has_key(name2):
                            self.matrix[name2]={}
                            self.matrix[name2]={}
                        self.matrix[name2][name1]=[ene,0.0,0.0,0.0]
                        self.distmatrix[name2][name1]=dist
        #
        # Write the matrix file
        #
        if filename:
            import pKaIO
            X=pKaIO.pKaIO()
            X.matrix=self.matrix
            X.write_matrix(filename+'.MATRIX.DAT')
        return self.matrix
Exemplo n.º 16
0
def device_pixels(cr, x):
  x = float(x)
  px,py = cr.device_to_user_distance(x,0.);
  return geometry.length(px,py)
Exemplo n.º 17
0
    def calculate_matrix(self, filename=None, eps=8, exdi=80, updater=None):
        """
        # This function calculates a simplified version of the charge-charge interaction
        # energy matrix
        #
        #
        # Calculate the factor that converts formal charges and distances in A into kT energies
        # eps is the dielectric constant
        """
        factor = (1.0 /
                  (4.0 * pi * e0)) * (e * e / A) * 1.0 / eps * 1.0 / (k * T)
        #
        # Get the fast scaled accessibility
        #
        acc = self.get_atoms_around(updater=updater)
        #
        # And now we calculate the matrix
        #
        import string
        if not getattr(self, 'titratable_groups', None):
            self.get_titratable_groups()
        self.matrix = {}
        self.distmatrix = {}
        titgrps = self.titratable_groups
        residues = titgrps.keys()
        residues.sort()
        #
        # Get the total number of calcs
        #
        ncalcs = len(residues) * len(residues)
        count = 0
        for residue in residues:
            for group in titgrps[residue]:
                name1 = self.get_titgroup_name(residue, group)
                if not self.matrix.has_key(name1):
                    self.matrix[name1] = {}
                if not self.distmatrix.has_key(name1):
                    self.distmatrix[name1] = {}
                #
                # Calculate distance from center of atoms
                #
                x = 0.0
                y = 0.0
                z = 0.0
                for atom in group['atoms']:
                    x = x + self.atoms[residue + ':' + atom]['X'] / float(
                        len(group['atoms']))
                    y = y + self.atoms[residue + ':' + atom]['Y'] / float(
                        len(group['atoms']))
                    z = z + self.atoms[residue + ':' + atom]['Z'] / float(
                        len(group['atoms']))
                #
                # Now for the second residue
                #
                for residue2 in titgrps.keys():
                    for group2 in titgrps[residue2]:
                        if not updater is None:
                            updater('%d of %d (%4.1f%% completed)' %
                                    (count, ncalcs,
                                     float(count) / float(ncalcs) * 100.0))
                        count = count + 1
                        name2 = self.get_titgroup_name(residue2, group2)
                        if self.matrix[name1].has_key(name2):
                            continue
                        #
                        # Get center of atoms for this res
                        #
                        x2 = 0.0
                        y2 = 0.0
                        z2 = 0.0
                        for atom in group2['atoms']:
                            x2 = x2 + self.atoms[residue2 + ':' +
                                                 atom]['X'] / float(
                                                     len(group2['atoms']))
                            y2 = y2 + self.atoms[residue2 + ':' +
                                                 atom]['Y'] / float(
                                                     len(group2['atoms']))
                            z2 = z2 + self.atoms[residue2 + ':' +
                                                 atom]['Z'] / float(
                                                     len(group2['atoms']))
                        #
                        # Get the distance
                        #
                        v1 = numpy.array([x, y, z])
                        v2 = numpy.array([x2, y2, z2])
                        import geometry
                        dist = geometry.length(v1 - v2)

                        if dist != 0:
                            crg1 = group['charge']
                            crg2 = group2['charge']
                            ene = factor * float(crg1 * crg2) / (math.pow(
                                dist, 1.5))
                            #
                            # Get the influence of the acc
                            #
                            acc_frac = math.sqrt(acc[name1] * acc[name2])
                            acc_frac = math.pow(acc_frac, 2.0)
                            ene = ene * 1.99 * acc_frac + (
                                1.0 -
                                acc_frac) * float(eps) / float(exdi) * ene
                        else:
                            ene = 0.0
                        #if ene:
                        #    print '%20s - %20s: %7.3f' %(name1,name2,ene)
                        self.matrix[name1][name2] = [ene, 0.0, 0.0, 0.0]
                        self.distmatrix[name1][name2] = dist
                        if not self.matrix.has_key(name2):
                            self.matrix[name2] = {}
                            self.matrix[name2] = {}
                        self.matrix[name2][name1] = [ene, 0.0, 0.0, 0.0]
                        self.distmatrix[name2][name1] = dist
        #
        # Write the matrix file
        #
        if filename:
            import pKaIO
            X = pKaIO.pKaIO()
            X.matrix = self.matrix
            X.write_matrix(filename + '.MATRIX.DAT')
        return self.matrix