Repository navigation
Expand file tree
/
Copy pathcif2Csv.py
More file actions
executable file
·74 lines (59 loc) · 2.11 KB
/
Copy pathcif2Csv.py
File metadata and controls
executable file
·74 lines (59 loc) · 2.11 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python3
import sys
import cifLib.helpL as hlp
import cifLib.cliParsing as cliP
import cifLib.cifFinder as fnd
import cifLib.fmtParsing as fmt
import cifLib.miscellaneous as misc
import cifMod.printStuff as pS
import cifMod.processing as proc
from gemmi import cif # type: ignore
import os
from pymatgen.core.structure import Structure
# file_struct = Structure.from_file(cif_path)
def main(argv):
myOptDict = cliP.getMyOptDict1(argv)
pSignal = cliP.getParsedSignals(argv, myOptDict)
pS.handleSignal(argv, pSignal)
myOptDict = cliP.getRefactoredOptDict(myOptDict)
if '-c' in myOptDict:
#The cif counting
inPath = misc.rmTrailSlash(argv[1])
print(fnd.getCifCount(inPath))
sys.exit()
if '-p' in myOptDict:
#The cif printing
inPath = misc.rmTrailSlash(argv[1])
fnd.printPath(inPath, '-n' in myOptDict)
sys.exit()
inPath, fmtFile, outCsv = argv[1:4]
fmtStrList=fmt.getStrFmtList1(fmtFile)
if '-H' in myOptDict:
header='#'+fmt.getStrFmt(fmtFile)
inPath = misc.rmTrailSlash(inPath)
fileOp='w'
if '-a' in myOptDict:
fileOp='a'
with open(outCsv, fileOp) if outCsv != '-'\
else sys.stdout as f:
if '-H' in myOptDict:#Just writting the header
f.write(header+'\n')
if '--tee' in myOptDict:
print(header)
for cRoute in fnd.yieldCifRoute(inPath):
block = fmt.getBlock(cRoute)
pymat_struct = fmt.getStructure(cRoute)
evalList=[str(misc.myEval(e, block, pymat_struct)) for e in fmtStrList]
if 'None' in evalList:
sys.stderr.write("warning: %s has a None\n" %(cRoute))
if '-l' in myOptDict:
with open(myOptDict['-l'], 'a') as lF:
lF.write("warning: %s has a None\n" %(cRoute))
if '-N' in myOptDict:
continue
csvStr = ", ".join(evalList)
f.write(csvStr+'\n')
if '--tee' in myOptDict:
print(csvStr)
if __name__ == "__main__":
main(sys.argv)