import glob, os
import pyworkflow.em.packages.relion as relion
import pyworkflow.em.metadata as md
import datetime
initTime = datetime.datetime.now()
fnStar='particles_data.star'
#fnStar='shiny_200.star'
emxOutfile = open("10025.emx", "w")
micrographString="""
%4.2f
%4.2f
%4.1f
%2.1f
"""
particleString="""
%0.1f
%0.1f
"""
emxOutfile.write("""
'
""")
oldMic="kk"
#read relion star file
mdStar = md.MetaData(fnStar)
for imgRow in md.iterRows(mdStar):
micName = imgRow.getValue(md.RLN_MICROGRAPH_NAME)
if oldMic == micName:
pass
else:
oldMic = micName
voltage = imgRow.getValue(md.RLN_CTF_VOLTAGE)
cs = imgRow.getValue(md.RLN_CTF_CS)
cameraPixelSize = imgRow.getValue(md.RLN_CTF_DETECTOR_PIXEL_SIZE)
magnification = imgRow.getValue(md.RLN_CTF_MAGNIFICATION)
sampling = cameraPixelSize * 10000 / magnification
emxOutfile.write(micrographString%(micName,sampling,sampling,voltage,cs))
oldMic="kk"
index = 1
mdStar = md.MetaData(fnStar)
for imgRow in md.iterRows(mdStar):
partNameAux = imgRow.getValue(md.RLN_IMAGE_NAME)
partName = partNameAux[7:]
index = int(partNameAux[0:6])
micName = imgRow.getValue(md.RLN_MICROGRAPH_NAME)
x = imgRow.getValue(md.RLN_IMAGE_COORD_X)
y = imgRow.getValue(md.RLN_IMAGE_COORD_Y)
#if oldMic == micName:
# index += 1
#else:
# oldMic = micName
# index=1
emxOutfile.write(particleString%(partName,index,x,y,micName))
emxOutfile.write("")
b = datetime.datetime.now()
print("Time (h,m,s)",b-initTime)