Example #1
0
    def _hls2rgb(self,h):
        """
        We use a rescaled h \in [0,1]

        h von 0 .. 360 

       letztes argument ist ein flag 0 oder 1, der entscheided ob
       die gruenen farben noch staerker auseinandergezogen werden,
       da wir gruen so gut sehen koennen.
       sonst: l = 0.5, s = 1 ist meist sinnvoll,
                    l = 0: schwarz, l=1 weiss, s: saettigung

        """
        h=h**self.exponent
        if(self.invert): h=1.0-h
        h=h*360.0
        h=Numeric.fmod(h,360.0)
        if(self.hls_hls):
            h=h/60.0
        else:
            if(h<120):
                h=h/120.0       #    /* 0..1 Rot..(Orange)..Gelb */
            elif(h<180):
                h=h/60.0 - 1.0  #     /* 1..2 Gelb..Gruen */
            elif(h<240):
                h=h/30.0 - 4.0 #     /* 2..4 Gruen..Blaugruen..Blau*/
            else:
                h=h/60.0        #     /* 4..6 Blau..Purpur..Rot */
        c=int(h)
        frac=h-c
        if (self.hls_l<=0.5):
            maxi=self.hls_l*(1.0+self.hls_s)
        else:
            maxi=self.hls_l+self.hls_s-self.hls_l*self.hls_s
        mini=2*self.hls_l-maxi;
        diff=maxi-mini;
        if(self.hls_s==0):            #                            /* grau */
            return(1.0,1.0,1.0) 
        else:
            if(c==0):
                return(maxi,mini+frac*diff,mini)
            elif(c==1):
                return(mini+(1.0-frac)*diff,maxi,mini)
            elif(c==2):
                return(mini,maxi,mini+frac*diff)
            elif(c==3):
                return(mini,mini+(1.0-frac)*diff,maxi)
            elif(c==4):
                return(mini+frac*diff,mini,maxi)
            else:
                return(maxi,mini,mini+(1.0-frac)*diff)
Example #2
0
    def addImproperTerm(self, data, improper, object, global_data):
        if not self.arguments[2]:
            return
	a1 = improper.a1
	a2 = improper.a2
	a3 = improper.a3
	a4 = improper.a4
	i1 = a1.index
	i2 = a2.index
	i3 = a3.index
	i4 = a4.index
	t1 = global_data.atom_type[a1]
	t2 = global_data.atom_type[a2]
	t3 = global_data.atom_type[a3]
	t4 = global_data.atom_type[a4]
	terms = self.dataset.improperParameters(t1, t2, t3, t4)
	if terms is not None:
	    atoms = [(t2,i2,a2), (t3,i3,a3), (t4,i4,a4)]
	    atoms.sort(_order)
	    i2, i3, i4 = tuple(map(lambda t: t[1], atoms))
	    a2, a3, a4 = tuple(map(lambda t: t[2], atoms))
            v1 = a2.position()-a3.position()
            v2 = a3.position()-a1.position()
            v3 = a4.position()-a1.position()
            a = v1.cross(v2).normal()
            b = v3.cross(v2).normal()
            cos = a*b
            sin = b.cross(a)*v2/v2.length()
            dihedral = Transformation.angleFromSineAndCosine(sin, cos)
            if dihedral > Numeric.pi:
                dihedral = dihedral - 2.*Numeric.pi
	    for p in terms:
		if p[2] != 0.:
                    mult = p[0]
                    phase = Numeric.fmod(Numeric.pi-mult*dihedral,
                                         2.*Numeric.pi)
                    if phase < 0.:
                        phase = phase + 2.*Numeric.pi
		    data.add('dihedrals', (i2, i3, i1, i4,
                                           p[0], phase) + p[2:])
Example #3
0
    def addDihedralTerm(self, data, dihedral, object, global_data):
        if not self.arguments[2]:
            return
	a1 = dihedral.a1
	a2 = dihedral.a2
	a3 = dihedral.a3
	a4 = dihedral.a4
	i1 = a1.index
	i2 = a2.index
	i3 = a3.index
	i4 = a4.index
	global_data.add('1_4_pairs', (i1, i4))
	t1 = global_data.atom_type[a1]
	t2 = global_data.atom_type[a2]
	t3 = global_data.atom_type[a3]
	t4 = global_data.atom_type[a4]
	terms = self.dataset.dihedralParameters(t1, t2, t3, t4)
	if terms is not None:
            v1 = a1.position()-a2.position()
            v2 = a2.position()-a3.position()
            v3 = a4.position()-a3.position()
            a = v1.cross(v2).normal()
            b = v3.cross(v2).normal()
            cos = a*b
            sin = b.cross(a)*v2/v2.length()
            dihedral = Transformation.angleFromSineAndCosine(sin, cos)
            if dihedral > Numeric.pi:
                dihedral = dihedral - 2.*Numeric.pi
	    for p in terms:
		if p[2] != 0.:
                    mult = p[0]
                    phase = Numeric.fmod(Numeric.pi-mult*dihedral,
                                         2.*Numeric.pi)
                    if phase < 0.:
                        phase = phase + 2.*Numeric.pi
		    data.add('dihedrals', (i1, i2, i3, i4,
                                           p[0], phase) + p[2:])
Example #4
0
def angles(imagefilename):
    im=Image.open(imagefilename)
    #im.thumbnail((20,50))
    for i in range(0):
        im=im.filter(ImageFilter.SMOOTH)

    img=Numeric.reshape(Numeric.fromstring(im.convert("L").tostring(),
                                                Numeric.UnsignedInt8),
                             (im.size[1],im.size[0]))

    img=img.astype(Numeric.Complex16)


#    img_freq=FFT.fft2d(img)
    gsize=11
    sigma=1
    gauss=iagaussian([gsize,gsize],[gsize//2,gsize//2],
                     [[sigma,0],[0,sigma]]).astype(Numeric.Complex16)
    #print Numeric.array2string(gauss,precision=3,suppress_small=1)
#    kernel_freq=FFT.fft2d(gauss)

    sys.stdout.write("convolve...")
    sys.stdout.flush()
    img=iaconv(img,gauss)
    print "done"

#    img=FFT.inverse_fft2d(img_freq)

    # we can skip borders, which have blur errors anyhow
    margin=gsize
    img=img[margin:-1-margin,margin:-1-margin]

    view(img)

    ix=deriv(img,0)
    view(ix)

    iy=deriv(img,1)
    view(iy)

    x=ix-iy*1j
    angs=Numeric.fmod(-Numeric.arctan2(x.imag,x.real)+pi,pi)
    mags=abs(Numeric.sqrt(ix*ix+iy*iy))

    view(angs)
    
    histo={} # angle:freq
    degreesperbucket=.1
    buckets=180/degreesperbucket
    totalcounted=0
    for ang,mag in zip(Numeric.ravel(angs),Numeric.ravel(mags)):
        ang=int(ang*buckets)/buckets
        histo[ang]=histo.get(ang,0)+mag
        totalcounted+=mag

    keys=histo.keys()
    keys.sort()
    f=open("angles.data",'w')
    for k in keys:
        degrees=k*360/(2*pi)
        print >>f,"%.3f %f" % (degrees,histo[k])

        # remark on counts that are more than 1% of the total
        if histo[k]>totalcounted*.005:
            print "peak at",degrees