import olx
import olex
#import olex_core
import glob
from olexex import SpyVar
import OlexVFS
from olexFunctions import OV
def BatchMatch(dirStr, t='cif'):
OV.SetVar("batch_dir" ,"%s" %dirStr)
g = glob.glob("%s\\*.%s" %(dirStr, type))
outStr = ""
outData = ""
print("Found %i files of type %s in Directory %s" %(len(g), type, dirStr))
if g:
wFile = open("%s\\match.csv" %dirStr, 'w')
wFile.write("Match Results\n")
wFile.close()
#olx.StartLogging("'%s\\match.log'" %dirStr)
print(r'Matching info of %i files of type %s in Directory %s' %(len(g), t, dirStr))
print(r'Generated by Olex2, Compile Version %s' %(olx.GetCompilationInfo()))
for structure in g:
SpyVar.MatchedRms = []
st = "'%s'" %structure
stName = structure.split('\\')[-1:][0]
outStr += '
%s ' %(st, stName)
try:
olx.Atreap(structure)
except:
outStr += 'NOT READ - THERE IS A PROBLEM WITH THIS FILE: %s' %(structure)
continue
print(r"%s" %(structure))
try:
olx.Kill("$h")
olx.Fuse()
except:
pass
n_frags = int(olx.xf.latt.GetFragmentCount())
n_frags_count = ""
for i in range(n_frags):
c = len((olx.xf.latt.GetFragmentAtoms(i)).split(","))
n_frags_count+= "%i " %c
if c == 1:
atom = olx.xf.latt.GetFragmentAtoms(i)
if atom[0] != 'H':
olx.Kill(atom)
n_frags_count = n_frags_count.strip()
outStr += '%s Fragments (%s) ' %(n_frags, n_frags_count)
outStr += 'UnMatch
'
outData += "\n%s," %stName
outData += "%s," %n_frags
outData += "%s," %n_frags_count
olx.Match('-i')
if not SpyVar.MatchedRms:
outStr += 'No Match found
'
outData += "NO MATCH"
else:
outStr, outData = createRMSDisplay(outStr, outData)
#outStr, outData = CheckInvertedMatch(outStr, outData)
outStr += '
'
OlexVFS.write_to_olex('batchmatchlist.htm', outStr)
wFile = open("%s\\match.csv" %dirStr, 'a')
wFile.write(outData)
wFile.close()
OlexVFS.write_to_olex('batchmatchlog.csv', outStr)
#olx.Stop('logging')
olex.m('updatehtml')
OV.registerMacro(BatchMatch, "t")
def CheckInvertedMatch(outStr, outData):
limes = len(SpyVar.MatchedFragments) -1
i = 0
for f in SpyVar.MatchedFragments:
if i == limes:
break
fragID = SpyVar.MatchedFragments[f].get('fragID')
SpyVar.MatchedRms = []
olx.Inv('%s -f' %f)
olx.Match()
outStr += "
Inverted Fragment %s
" %fragID
outStr, outData = createRMSDisplay(outStr, outData)
i += 1
return outStr, outData
def createRMSDisplay(outStr, outData):
for rms in SpyVar.MatchedRms:
if rms < 0.2:
outStr += '%.4f ' %(rms)
elif rms < 1:
outStr += '%.4f ' %(rms)
elif rms < 2:
outStr += '%.4f ' %(rms)
else:
outStr += '%.4f ' %(rms)
outData += "%.4f," %rms
return outStr, outData