2013-07-12 5 views
1

여름 인턴쉽을 위해 파이썬으로 코드를 작성했습니다. 당신이 볼 수 있듯이파이썬 브로큰 파이프

from numpy import loadtxt, abs, mean, float64 



def Sum_radii(particle1, particle2): #Sum of radii - to be compared with distance 
    summ = particle1.radius+particle2.radius 
    return summ 


def PBCdist(particle1, particle2): #PBC conditions to compute distance for any two particles 
    dx = abs(particle1.x-particle2.x) 
    dy = abs(particle1.y-particle2.y) 
    #dz = abs(particle1.z-particle2.z) 
    if dx > 0.5: 
     dx = 1.0-dx 
    else: 
     dx = dx 
    if dy > 0.5: 
     dy = 1.0-dy 
    else: 
     dy = dy 
    #if dz > 0.5: 
    # dz = 1.0-dz 
    #else: 
    # dz = dz 
    DX = dx**2 
    DY = dy**2 
    #DZ = dz**2 
    dist = DX+DY 
    distance = dist**0.5 

    return distance 

def Final_step(my_particles): 
    for particle1 in my_particles:    
     if len(particle1.neighbours) <=2 : 

      for k in range(len(particle1.neighbours)): 
       n = particle1.neighbours[k] 
       my_particles[n].neighbours.remove(particle1.n) 
    for particle1 in my_particles: 
     if len(particle1.neighbours) <=2 : 
      my_particles.remove(particle1) 
    return my_particles 


def Recursion(my_particles): 
    l1 = len(my_particles) 
    my_particles = Final_step(my_particles) 
    l2 = len(my_particles) 
    if (l1!=l2): 
     Recursion(my_particles) 
    else: 
     return my_particles  
    f = open("contacts.txt", "w") 
    for i in range(len(my_particles)): 



     list = [] 

     list.append(my_particles[i].n,my_particles[i].neighbours) 
     print list 

     print >>f, list 

    f.close() 

def mean_contacts(my_particles): 

    for k in range(len(my_particles)): 
       contact_number.append(len(my_particles[k].neighbours)) 

    print ("%.20f" % mean(contact_number)) 
#Read data and define the class Particle 

class Particle(): 
    def __init__(self, (x,y), n, radius, neighbours): 

     self.n = n 
     self.x = x 
     self.y = y 
     #self.z = z 
     self.radius = radius 
     self.neighbours = neighbours   



number = loadtxt("Final.dat", usecols=(0,), unpack=True, dtype = int) 
c1,c2,r = loadtxt("Final.dat", usecols=(1,2,4), unpack=True, dtype=float64) 



number_of_particles = len(number) 
my_particles  = [] 
overlap    = [] 
contact_number  = [] 



for i in range(number_of_particles): 
    n = number[i] 
    x = c1[i] 
    y = c2[i] 
    #z = c3[i] 
    radius = r[i] 
    neighbours = [] 



    particle = Particle((x,y), n, radius, neighbours) 
    my_particles.append(particle) 





for particle1 in my_particles: 
    for particle2 in my_particles: 
     distance = PBCdist(particle1, particle2) 
     sum_of_radii = Sum_radii(particle1, particle2) 
     if (distance < sum_of_radii) and (distance>0): 
      olap = sum_of_radii - distance 
      overlap.append(olap) 
      particle1.neighbours.append(particle2.n) 



#Recursion(my_particles) 


Final_step(my_particles) 
mean_contacts(my_particles) 

, 나는 재귀 함수를 시도하지 않은 단지 일을 더 간단하게 : 여기

는 코드입니다.

이제, 파일은 읽기는 다음과 같은 방식으로 서식이 메신저 : 데이터의

0 0.70138224747245225821 0.28586219648439409324 0 0.0037570717610070714435 
1 0.94878397047547669008 0.17267104541971631249 0 0.0038326670080525947204 
2 0.59078448810638095612 0.29243415714920478754 0 0.0037315418643608781225 
3 0.38696755396911874936 0.15180438637928708734 0 0.004051606114197996676 2 
4 0.71585843878867627676 0.47742962311059283786 0 0.0043035198430089825067 

16383에 대한 행.

Exception in thread Thread-1: 
Traceback (most recent call last): 
    File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner 
    self.run() 
    File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/monitor.py",  line 575, in run 
    already_pickled=True) 
    File "/usr/lib/python2.7/dist-packages/spyderlib/utils/bsdsocket.py", line 24, in  write_packet 
    sock.send(struct.pack("l", len(sent_data)) + sent_data) 
error: [Errno 32] Broken pipe 

내가 128 행 데이터 파일과 그것을 시도하고 일을 1 초 이내에 완벽하게 작동 : 나는 4 분 같은 후 코드를 실행하려고 할 때 다음과 같은 오류 메시지가 나타납니다.

나는 그 메시지가 처음에 무엇을 의미하는지, 가능하다면 그것을 고치는 방법을 궁금해했다.

저는 Ubuntu12.04, 4GB RAM, 64 비트 데스크탑에서 실행됩니다.

+1

[업데이트] (https://code.google.com/p/spyderlib/issues/detail?id=1474) 스파이더. – jorgeca

+0

전체 추적입니까? –

답변

0

Issue 1474 (Issue 1106)에 따르면 Spyder 2.1.10의 알려진 문제인 것 같습니다.

수정 프로그램은 Spyder 2.2에서 사용할 수있는 것 같습니다.

관련 문제