-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
117 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
from utils import read_xyz, write_xyz | ||
import sys | ||
sys.path.append('./src/utils') | ||
|
||
# Replicar a célula unitária com os nanocracks lineares (n2) | ||
|
||
|
||
def replicate_cell(atoms, lattice_constants, n_replications_x, n_replications_y, crack_size): | ||
replicated_atoms = [] | ||
for i in range(n_replications_x): | ||
for j in range(n_replications_y): | ||
for index, (atom, position) in enumerate(atoms): | ||
# POSICOES PERMANECEM CONSTANTES | ||
new_position = [ | ||
position[0] + (lattice_constants[0]) * i, position[1] + (lattice_constants[1])*j, 0.0] | ||
|
||
if i == (n_replications_x // 2 - 1): # meio - 1 (lateral left) (6) | ||
floor = int(n_replications_y//2 - | ||
((crack_size - 1)/2) + 1) # 5 | ||
ceiling = int(n_replications_y//2 + | ||
((crack_size - 1)/2) - 1) # 9 | ||
if j in range(floor, ceiling+1): | ||
atom = 'H' | ||
if (j == floor and index in [0, 1, 2, 8, 9]) or (j == ceiling and index in [5, 6, 7, 8, 9]): | ||
replicated_atoms.append((atom, new_position)) | ||
else: | ||
if index in [8, 9]: | ||
replicated_atoms.append((atom, new_position)) | ||
else: | ||
replicated_atoms.append((atom, new_position)) | ||
|
||
elif i == (n_replications_x // 2): # meio (7) | ||
floor = int(n_replications_y//2 - | ||
((crack_size - 1)/2)) # 4 | ||
ceiling = int(n_replications_y//2 + | ||
((crack_size - 1)/2)) # 10 | ||
if j in range(floor, ceiling+1): | ||
atom = 'H' | ||
if (j == floor and index in [0, 1, 2, 3, 4, 8, 9]) or (j == ceiling and index in [3, 4, 5, 6, 7, 8, 9]): | ||
replicated_atoms.append((atom, new_position)) | ||
else: | ||
replicated_atoms.append((atom, new_position)) | ||
|
||
elif i == (n_replications_x // 2 + 1): # meio + 1 (lateral right) (8) | ||
floor = int(n_replications_y//2 - | ||
((crack_size - 1)/2) + 1) # 5 | ||
ceiling = int(n_replications_y//2 + | ||
((crack_size - 1)/2) - 1) # 9 | ||
if j in range(floor, ceiling+1): | ||
atom = 'H' | ||
if (j == floor and index in [0, 1, 2, 3, 4]) or (j == ceiling and index in [3, 4, 5, 6, 7]): | ||
replicated_atoms.append((atom, new_position)) | ||
else: | ||
if index in [3, 4]: | ||
replicated_atoms.append((atom, new_position)) | ||
else: | ||
replicated_atoms.append((atom, new_position)) | ||
else: | ||
replicated_atoms.append((atom, new_position)) | ||
return [len(replicated_atoms), replicated_atoms] | ||
|
||
|
||
# Vetores de rede (lattice constants) | ||
a = 6.3028 | ||
b = 4.9302 | ||
lattice_constants = [a, b] | ||
|
||
# Parâmetros | ||
INPUT_UNIT_CELL_FILE = 'src/simulations/unit_cell.xyz' | ||
OUTPUT_STRUCTURE_FILE = 'src/simulations/n1_nanocrack_structure.xyz' | ||
n_replications_x = 17 | ||
n_replications_y = 17 | ||
crack_size = 7 | ||
|
||
OUTPUT_STRUCTURE_FILE = 'src/simulations/n1_nanocrack_structure.xyz' | ||
|
||
# Ler a célula unitária | ||
n_atoms, comment, atoms = read_xyz(INPUT_UNIT_CELL_FILE) | ||
|
||
# Replicar a célula unitária | ||
replicated_atoms = replicate_cell( | ||
atoms, lattice_constants, n_replications_x, n_replications_y, crack_size) | ||
|
||
n_atoms_modified = replicated_atoms[0] | ||
atoms_modified = replicated_atoms[1] | ||
|
||
# Escrever o arquivo .xyz com a estrutura replicada | ||
write_xyz(OUTPUT_STRUCTURE_FILE, n_atoms_modified, comment, atoms_modified) | ||
|
||
print('Estrutura replicada, arquivo salvo em {}'.format(OUTPUT_STRUCTURE_FILE)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
def read_xyz(file): | ||
with open(file, 'r') as f: | ||
n_atoms = int(f.readline()) | ||
comment = f.readline() | ||
atoms = [] | ||
for line in f: | ||
atom, x, y, z = line.split() | ||
atoms.append((atom, [float(x), float(y), float(z)])) | ||
return n_atoms, comment, atoms | ||
|
||
|
||
def write_xyz(file, n_atoms, comment, atoms): | ||
with open(file, 'w') as f: | ||
f.write(str(n_atoms) + '\n') | ||
f.write(comment) | ||
for atom, position in atoms: | ||
x = format(position[0], '.16f') | ||
y = format(position[1], '.16f') | ||
z = format(position[2], '.16f') | ||
f.write('{} {} {} {}\n'.format(atom, x, y, z)) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +0,0 @@ | ||
import math | ||
|
||
hip = 1.42 | ||
cateto = math.sqrt((hip**2) / 2) # 1.0023 | ||
|
||
a = 6.3028 | ||
b = 4.9302 | ||
x = (a - ((2*cateto) + (2*hip))) / 2 # 0.7238 | ||
y = (b - (hip + (2*cateto))) / 2 # 0.75 | ||
|
||
x1 = [x+cateto, y, 0.0] | ||
x2 = [x+cateto+hip, y, 0.0] | ||
x3 = [x+cateto+(2*hip), y, 0.0] | ||
|
||
x4 = [x+(2*cateto)+(2*hip), y+cateto, 0.0] | ||
x5 = [x+(2*cateto)+(2*hip), y+cateto+hip, 0.0] | ||
|
||
x6 = [x+cateto+(2*hip), y+(2*cateto)+hip, 0.0] | ||
x7 = [x+cateto+hip, y+(2*cateto)+hip, 0.0] | ||
x8 = [x+cateto, y+(2*cateto)+hip, 0.0] | ||
|
||
x9 = [x, y+cateto+hip, 0.0] | ||
x10 = [x, y+cateto, 0.0] | ||
|
||
|
||
def padraoAtomo(atomo): | ||
x, y, z = atomo | ||
x = format(x, '.16f') | ||
y = format(y, '.16f') | ||
z = format(z, '.16f') | ||
return f"C {x} {y} {z}" | ||
|
||
|
||
lista = [x1, x2, x3, x4, x5, x6, x7, x8, x9, x10] | ||
listaPadrao = [padraoAtomo(atomo) for atomo in lista] | ||
|
||
with open('tests/test.xyz', 'w') as file: | ||
file.write(str(len(listaPadrao)) + '\n') | ||
for atomo in listaPadrao: | ||
file.write(atomo + '\n') | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.