From 92a00d2e59f0ef4988d7570f9735f1f4342c6193 Mon Sep 17 00:00:00 2001 From: Leo gaspard Date: Thu, 9 May 2019 08:19:00 +0200 Subject: [PATCH] Pattern recognition amelioration --- DOC.md | 8 +++++--- README.md | 2 +- crystal_met.py | 30 +++++++++++++++++++----------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/DOC.md b/DOC.md index 194880a..146ec07 100644 --- a/DOC.md +++ b/DOC.md @@ -10,11 +10,13 @@ There is no obligation to put any order in the keywords * OUTPUT output_file_name -* PATTERN nAtom1 labelAtom1 nAtom2 labelAtom2 ... +* PATTERN + nAtom1 labelAtom1 nAtom2 labelAtom2 ... + ... + NRETTAP -Not that, if you have more than once the Atom1, you will have to place it again at the end (for example, 5 Ir 8 Sr 6 O 5 Ir) -* NPATTERN nPattern +* NPATTERN nPattern1 nPattern2 ... * LATTICE diff --git a/README.md b/README.md index a7357e6..b3ea67c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ -Crystal MET (Crystal Maker Effective Tool) is a python3 programs that helps you building a system using only the informations taken from a CIF file. +Crystal MET (Crystal Maker Effective Tool) is a python3 programs, developped during an internship at the [LCPQ](www.lcpq.ups-tlse.fr) that helps you building a system using only the informations taken from a CIF file. Use it with care, always check the output, it may work differently from what you expect. diff --git a/crystal_met.py b/crystal_met.py index 01ee51d..64f996d 100644 --- a/crystal_met.py +++ b/crystal_met.py @@ -28,8 +28,8 @@ yAxis = 'x' zAxis = 'x' sym = 'x' output_file = 'x' -pattern = 'x' -npattern = 'x' +pattern = [] +npattern = [] atoms = 'x' dist = 'x' lattice = 'x' @@ -194,13 +194,19 @@ def read_input(inputFile): output_file = line[1] elif line[0] == 'PATTERN': pattern = [] - for i in range(1,len(line)): - if i%2 == 1: - pattern.append(int(line[i])) - else: - pattern.append(line[i]) + line = f.readline() + while line.strip() != 'NRETTAP': + pattern.append([]) + line = line.split() + for i in range(len(line)): + if i%2 == 0: + pattern[-1].append(int(line[i])) + else: + pattern[-1].append(line[i]) + line = f.readline() elif line[0] == 'NPATTERN': - npattern = int(line[1]) + for i in range(1,len(line)): + npattern.append(int(line[i])) elif line[0] == 'LATTICE': a = float(f.readline().split()[1]) b = float(f.readline().split()[1]) @@ -336,7 +342,7 @@ def set_pp(rPP,coords, notIn): #Select which atoms are in the first shell of pse now = datetime.datetime.now() printProgressBar(start,now,i+1,len(coords),prefix='Finding the first shell',length=50) for j in range(len(coords)): - if coords[i][4] != 'O' or dist_zero(coords[j]) > 2*(max([atoms[k] for k in range(3,len(atoms),4)])*npattern+rPP): + if coords[i][4] != 'O' or dist_zero(coords[j]) > 2*(max([atoms[k] for k in range(3,len(atoms),4)])*sum(npattern)+rPP): break if coords[i][4] == 'O': if coords[j][4] == 'C' and coords[j][3] not in notIn: @@ -351,6 +357,7 @@ def find_frag(pattern, n, coords): #the fragment according to user input inFrag = [] start = datetime.datetime.now() + inPattern = [] for k in range(n): closest = [100,100,100] now = datetime.datetime.now() @@ -359,7 +366,7 @@ def find_frag(pattern, n, coords): if j[3] == pattern[1]: if distance(j,[0,0,0]) < distance([0,0,0],closest) and [j[0],j[1],j[2],distance(j,j), coords.index(j)] not in inFrag: closest = [j[0],j[1],j[2],distance(j,j), coords.index(j)] - for i in range(1,len(pattern)//2): + for i in range(len(pattern)//2): inPattern = [closest] for j in range(int(pattern[2*i])): inPattern.append([100,100,100,distance([100,100,100],closest)]) @@ -744,7 +751,8 @@ def main(): coords = sorted(coords,key=dist_zero) coords = cut_bath(rBath,coords) - coords = find_frag(pattern, npattern ,coords) + for i in range(len(pattern)): + coords = find_frag(pattern[i], npattern[i],coords) coords = sorted(coords,key=operator.itemgetter(4)) coords = set_pp(rPP,coords,notIn) coords = sorted(coords,key=dist_zero,reverse=True)