Repository navigation
Expand file tree
/
Copy pathIOoperations.py
More file actions
78 lines (49 loc) · 2.05 KB
/
Copy pathIOoperations.py
File metadata and controls
78 lines (49 loc) · 2.05 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
75
76
77
78
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 20 16:35:29 2022
@author: Laura Stricker, laura.stricker@mat.ethz.ch
Input/output operations
"""
import os
import re
from importlib import reload
import numpy as np
import matplotlib.pyplot as plt
from dataclasses import make_dataclass
import SimulationBox
reload(SimulationBox)
from SimulationBox import SimulationBox
def naturalSort(myList):
'''Sort alphanumeric list'''
convert = lambda text: int(text) if text.isdigit() else text.lower()
alphanumericKey = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
return sorted(myList, key = alphanumericKey)
def defineIOFileNames(baseFolder,fileName):
'''Define name of input and output files, given the path'''
#Extract raw name, without .dat extension
rawFileName = fileName[0:len(fileName)-4]
inputFileName = baseFolder + '/Input/' + fileName
outputFileName = baseFolder + '/Output/' + rawFileName + '.xyz'
#Create class with name of files
fileNames = make_dataclass('fileNames', ['input', 'output', 'raw'])
#Create and return instance of class Name_files
return fileNames(inputFileName, outputFileName, rawFileName)
def defineSummaryOutputFileName(baseFolder):
fileNameSummary = 'summary.dat'
summaryOutputFileName = baseFolder + '/Output/' + fileNameSummary
os.makedirs(os.path.dirname(summaryOutputFileName), exist_ok=True)
return summaryOutputFileName
def extractInputFileList(baseFolder):
'''
Define list of input files with particle data, contained inside folder
.\input
'''
path = baseFolder + r'/Input/'
#List of files inside 'path'
files = os.listdir(path)
#Open files with the string ('keyword') in the name
keyword = "cluster_atoms"
particleFileList = [fileName for fileName in files if keyword in fileName]
particleFileList = naturalSort(particleFileList)
fileCount = len(particleFileList)
return particleFileList, fileCount