Trisurf Monte Carlo simulator
Samo Penic
2016-03-07 c14bd6e408bec0634a7cac3aa87e177562430afe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
î
ŠÝVýã@sºddlZddljjZddlZddlZddlZddlZddl    m
Z
ddl Z Gdd„dƒZ Gdd„dƒZ Gdd„dƒZGd    d
„d
ƒZdS) éN)Úislicec@sUeZdZdZdd„Zddd„Zdd„Zd    d
„Zd d „Zd S)ÚTapezHas all the info on the tapecCsdS)N©)Úselfrrú=/home/samo/programiranje/trisurf-ng/python/trisurf/trisurf.pyÚ__init__sz Tape.__init__Útapec    Cs9ytj|ƒ|_WntdƒtdƒYnXdS)Nz$Error reading or parsing tape file!
é)Ú    configobjÚ    ConfigObjÚconfigÚprintÚexit)rrrrrÚreadTapes
 
z Tape.readTapecCstjtj|ƒƒ|_dS)N)r
r ÚioÚStringIOr )rZstringrrrÚsetTape%sz Tape.setTapecCs |j|S)N)r )rÚkeyrrrÚgetValue)sz Tape.getValuecCsLd}x?|jjƒD].\}}|t|ƒdt|ƒd}qW|S)NÚz = Ú
)r Z    iteritemsÚstr)rZretvalrZvalrrrÚ__str__,s&z Tape.__str__N)    Ú__name__Ú
__module__Ú __qualname__Ú__doc__rrrrrrrrrrs    rc@sjeZdZdddd„Zdd„Zdd„Zd    d
„Zd d „Zd d„Zdd„Z    dS)Ú    DirectoryÚ.rcCs||_||_dS)N)ÚmaindirÚsimdir)rrr rrrr5s        zDirectory.__init__cCstjj|j|jƒS)N)ÚosÚpathÚjoinrr )rrrrÚfullpath:szDirectory.fullpathcCs*|jƒ}tjj|ƒr"dSdSdS)Nr    r)r$r!r"Úexists)rr"rrrr%=s zDirectory.existsc    CsHytj|jƒƒWn*td|jƒdƒtdƒYnXdS)NzCannot make directory rr    )r!Úmakedirsr$r r)rrrrÚmakeDs zDirectory.makecCs#|jƒdkr|jƒndS)Nr)r%r')rrrrÚmakeifnotexistLs zDirectory.makeifnotexistc    CsW|jƒrSytj|jƒƒWqStd|jƒdƒtdƒYqSXndS)NzCannot remove directory rr    )r%r!Úrmdirr$r r)rrrrÚremoveQs zDirectory.removec    Cs>ytj|jƒƒWn td|jƒdƒYnXdS)NzCannot go to directory r)r!Úchdirr$r )rrrrÚgotoZs
zDirectory.gotoN)
rrrrr$r%r'r(r*r,rrrrr4s          rc@sOeZdZddd„Zdd„Zdd„Zdd    „Zd
d „Zd S) Ú
Statisticszstatistics.csvcCs8||_||_tjj||ƒ|_|jƒdS)N)r"Úfilenamer!r#ÚfullnameÚread)rr"r.rrrrcs
        
zStatistics.__init__cCs t|jƒS)N)rr/)rrrrrjszStatistics.__str__cCs!tjj|jƒrdSdSdS)NTF)r!r"Úisfiler/)rrrrr%mszStatistics.existscCsWt|jdƒ}tj|jƒdƒ}d}|j}x|ƒrR|d7}q<W|S)Nzr+rr    )Úopenr/ÚmmapÚfilenoÚreadline)rÚfZbufÚlinesr5rrrÚmapcountss     zStatistics.mapcountcCsÞ|jƒr»|jƒ}yvt|jdƒ^}d}xN|D]F}|dkr\t|ƒn||dkryt|ƒn|d}q=WWdQXWqÚtd|jdƒtdƒYqÚXntd|jdƒtdƒdS)Nzr+rr    zCannot read statistics file in rzFile z does not exists.
)r%r8r2r/r r)rZnlinesZfinÚiÚlinerrrr0|s       zStatistics.readN)rrrrrr%r8r0rrrrr-bs
       r-c@seZdZdZddddd„Zdd„Zdd    „Zd
d „Zd d „Zdd„Z    dd„Z
ddd„Z ddd„Z dd„Z dS)ÚRunnerzS
    Class Runner consists of a single running or terminated instance of the trisurf
    Zrun0rcCsE||_|dkr%|j|ƒn|dkrA|j|ƒndS)Nr)ÚsubdirÚ initFromTapeÚinitFromSnapshot)rr<rÚsnapshotrrrr“s       zRunner.__init__cCs tƒ|_|jj|ƒdS)N)rrr)rrrrrr=œs zRunner.initFromTapec    Csytj|ƒ}WntdƒtdƒYnX|jƒ}|jdƒ}|jdƒ}tƒ|_|jj|j    ƒdS)NzError reading snapshot filer    rZtrisurfversion)
ÚETZparser rZgetrootÚfindrrrÚtext)rZ snapshotfileZtreeÚrootZtapetxtÚversionrrrr> s
  zRunner.initFromSnapshotcCsdS)Nrr)rrrrÚ    getStatus­szRunner.getStatuscCsv|jƒdkrhtd|jd|jƒ|_|jjƒ|jjƒtd|jjƒdƒn
tdƒdS)Nrrr z"Starting trisurf-ng executable at rz&Process already running. Not starting
)    rErrr<ÚDirr(r,r r$)rrrrÚstart°s  
z Runner.startcCsdS)Nr)rrrrÚstopºsz Runner.stopcCs‚d}xlt||ƒD][\}}|dkrSttt|jj|ƒƒƒ}n|jj|}|||}qW||_dS)Nz./Úxk0)ÚziprÚroundÚfloatrr r)rÚprefixÚ    variablesrÚpÚvZtvrrrÚ
setMaindir½s %    zRunner.setMaindircCs ||_dS)N)r<)rr<rrrÚ    setSubdirÈs    zRunner.setSubdirzstatistics.csvcCstd|ƒ|_dS)Nr)r-Ú
statistics)rZstatfilerrrÚ getStatisticsÌszRunner.getStatisticscCs2|jƒdkrd}nd}|jjƒ|S)Nrz  not running.z     running.)rErFr$)rrrrrrÐs    zRunner.__str__N)rrrrrr=r>rErGrHrQrRrTrrrrrr;s       
 r;)r
Zxml.etree.ElementTreeZetreeZ ElementTreer@Úbase64Úzlibrr!Z    itertoolsrr3rrr-r;rrrrÚ<module>s      .-