Skip to content

Commit

Permalink
style: autopep8 lint
Browse files Browse the repository at this point in the history
  • Loading branch information
caefleury committed Mar 30, 2024
1 parent 82b3d96 commit 6a416b1
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 75 deletions.
5 changes: 4 additions & 1 deletion src/scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
n2_crack.run('y')
replicate_cell.run()
print()
print("\033[1;32m" + "============================== Estruturas replicadas ===========================" + "\033[0m")
print(
"\033[1;32m" +
"============================== Estruturas replicadas ===========================" +
"\033[0m")
22 changes: 13 additions & 9 deletions src/scripts/n1_crack.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@


from my_utils import read_xyz, write_xyz
from n1_crack_utils import y_center_crack,x_center_crack
from n1_crack_utils import y_center_crack, x_center_crack


# Replicar a célula unitária com os nanocracks lineares (n2)
def replicate_n1_crack(atoms, lattice_constants, n_replications_x, n_replications_y, crack_size,crack_direction):
def replicate_n1_crack(atoms, lattice_constants, n_replications_x,
n_replications_y, crack_size, crack_direction):
replicated_atoms = []
for x in range(n_replications_x):
for y in range(n_replications_y):
Expand All @@ -15,7 +16,8 @@ def replicate_n1_crack(atoms, lattice_constants, n_replications_x, n_replication
position[0] + (lattice_constants[0]) * x, position[1] + (lattice_constants[1]) * y, 0.0]
if crack_direction == 'y':
if x == (n_replications_x // 2):
if y_center_crack(y, atom, n_replications_y, crack_size, index, new_position):
if y_center_crack(
y, atom, n_replications_y, crack_size, index, new_position):
atom, new_position = y_center_crack(
y, atom, n_replications_y, crack_size, index, new_position)
replicated_atoms.append((atom, new_position))
Expand All @@ -24,17 +26,17 @@ def replicate_n1_crack(atoms, lattice_constants, n_replications_x, n_replication

elif crack_direction == 'x':
if y == (n_replications_y // 2):
if x_center_crack(x, atom, n_replications_x, crack_size, index, new_position):
if x_center_crack(
x, atom, n_replications_x, crack_size, index, new_position):
atom, new_position = x_center_crack(
x, atom, n_replications_x, crack_size, index, new_position)
replicated_atoms.append((atom, new_position))
else:
replicated_atoms.append((atom, new_position))



return [len(replicated_atoms), replicated_atoms]


def run(crack_direction):
# Parâmetros
INPUT_UNIT_CELL_FILE = 'src/simulations/unit_cell.xyz'
Expand All @@ -54,7 +56,7 @@ def run(crack_direction):
# Replicar a célula unitária

replicated_atoms = replicate_n1_crack(
atoms, lattice_constants, n_replications_x, n_replications_y, crack_size,crack_direction)
atoms, lattice_constants, n_replications_x, n_replications_y, crack_size, crack_direction)

n_atoms_modified = replicated_atoms[0]
atoms_modified = replicated_atoms[1]
Expand All @@ -69,5 +71,7 @@ def run(crack_direction):

write_xyz(OUTPUT_STRUCTURE_FILE, n_atoms_modified, comment, atoms_modified)


print('Estrutura com rasgo n1 replicada no eixo {}, arquivo salvo em {}'.format(crack_direction,OUTPUT_STRUCTURE_FILE))
print(
'Estrutura com rasgo n1 replicada no eixo {}, arquivo salvo em {}'.format(
crack_direction,
OUTPUT_STRUCTURE_FILE))
10 changes: 7 additions & 3 deletions src/scripts/n1_edge_crack.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@


# Replicar a célula unitária com os nanocracks lineares (n2)
def replicate_edge_crack(atoms, lattice_constants, n_replications_x, n_replications_y, crack_size):
def replicate_edge_crack(atoms, lattice_constants,
n_replications_x, n_replications_y, crack_size):
replicated_atoms = []
for x in range(n_replications_x):
for y in range(n_replications_y):
Expand All @@ -15,7 +16,8 @@ def replicate_edge_crack(atoms, lattice_constants, n_replications_x, n_replicati
position[0] + (lattice_constants[0]) * x, position[1] + (lattice_constants[1]) * y, 0.0]

if x == (n_replications_x // 2):
if edge_center_crack(y, atom, n_replications_y, crack_size, index, new_position):
if edge_center_crack(
y, atom, n_replications_y, crack_size, index, new_position):
atom, new_position = edge_center_crack(
y, atom, n_replications_y, crack_size, index, new_position)
replicated_atoms.append((atom, new_position))
Expand All @@ -25,6 +27,7 @@ def replicate_edge_crack(atoms, lattice_constants, n_replications_x, n_replicati

return [len(replicated_atoms), replicated_atoms]


def run():
# Parâmetros
INPUT_UNIT_CELL_FILE = 'src/simulations/unit_cell.xyz'
Expand All @@ -51,4 +54,5 @@ def run():
# Escrever o arquivo .xyz com a estrutura replicada
write_xyz(OUTPUT_STRUCTURE_FILE, n_atoms_modified, comment, atoms_modified)

print('Estrutura com rasgo em borda n1 replicada, arquivo salvo em {}'.format(OUTPUT_STRUCTURE_FILE))
print('Estrutura com rasgo em borda n1 replicada, arquivo salvo em {}'.format(
OUTPUT_STRUCTURE_FILE))
32 changes: 21 additions & 11 deletions src/scripts/n2_crack.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@


from my_utils import read_xyz, write_xyz
from n2_crack_utils import y_left_crack, y_center_crack, y_right_crack,x_left_crack, x_center_crack, x_right_crack
from n2_crack_utils import y_left_crack, y_center_crack, y_right_crack, x_left_crack, x_center_crack, x_right_crack

# Replicar a célula unitária com os nanocracks lineares (n2)
def replicate_n2_crack(atoms, lattice_constants, n_replications_x, n_replications_y, crack_size,crack_direction):


def replicate_n2_crack(atoms, lattice_constants, n_replications_x,
n_replications_y, crack_size, crack_direction):
replicated_atoms = []
for x in range(n_replications_x):
for y in range(n_replications_y):
Expand All @@ -14,48 +17,54 @@ def replicate_n2_crack(atoms, lattice_constants, n_replications_x, n_replication
position[0] + (lattice_constants[0]) * x, position[1] + (lattice_constants[1]) * y, 0.0]
if crack_direction == 'y':
if x == (n_replications_x // 2 - 1):
if y_left_crack(y, atom, n_replications_y, crack_size, index, new_position):
if y_left_crack(y, atom, n_replications_y,
crack_size, index, new_position):
atom, new_position = y_left_crack(
y, atom, n_replications_y, crack_size, index, new_position)
replicated_atoms.append((atom, new_position))

elif x == (n_replications_x // 2):
if y_center_crack(y, atom, n_replications_y, crack_size, index, new_position):
if y_center_crack(
y, atom, n_replications_y, crack_size, index, new_position):
atom, new_position = y_center_crack(
y, atom, n_replications_y, crack_size, index, new_position)
replicated_atoms.append((atom, new_position))

elif x == (n_replications_x // 2 + 1):
if y_right_crack(y, atom, n_replications_y, crack_size, index, new_position):
if y_right_crack(
y, atom, n_replications_y, crack_size, index, new_position):
atom, new_position = y_right_crack(
y, atom, n_replications_y, crack_size, index, new_position)
replicated_atoms.append((atom, new_position))
else:
replicated_atoms.append((atom, new_position))
else:
if y == (n_replications_y // 2 - 1):
if x_left_crack(x, atom, n_replications_x, crack_size, index, new_position):
if x_left_crack(x, atom, n_replications_x,
crack_size, index, new_position):
atom, new_position = x_left_crack(
x, atom, n_replications_x, crack_size, index, new_position)
replicated_atoms.append((atom, new_position))

elif y == (n_replications_y // 2):
if x_center_crack(x, atom, n_replications_x, crack_size, index, new_position):
if x_center_crack(
x, atom, n_replications_x, crack_size, index, new_position):
atom, new_position = x_center_crack(
x, atom, n_replications_x, crack_size, index, new_position)
replicated_atoms.append((atom, new_position))

elif y == (n_replications_y // 2 + 1):
if x_right_crack(x, atom, n_replications_x, crack_size, index, new_position):
if x_right_crack(
x, atom, n_replications_x, crack_size, index, new_position):
atom, new_position = x_right_crack(
x, atom, n_replications_x, crack_size, index, new_position)
replicated_atoms.append((atom, new_position))
else:
replicated_atoms.append((atom, new_position))


return [len(replicated_atoms), replicated_atoms]


def run(crack_direction):
# Parâmetros
INPUT_UNIT_CELL_FILE = 'src/simulations/unit_cell.xyz'
Expand All @@ -74,12 +83,13 @@ def run(crack_direction):

# Replicar a célula unitária
replicated_atoms = replicate_n2_crack(
atoms, lattice_constants, n_replications_x, n_replications_y, crack_size,crack_direction)
atoms, lattice_constants, n_replications_x, n_replications_y, crack_size, crack_direction)

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 com rasgo n2 replicada, arquivo salvo em {}'.format(OUTPUT_STRUCTURE_FILE))
print('Estrutura com rasgo n2 replicada, arquivo salvo em {}'.format(
OUTPUT_STRUCTURE_FILE))
8 changes: 5 additions & 3 deletions src/scripts/replicate_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
# Replicar a célula unitária


def replicate_cell(atoms, lattice_constants, n_replications_x, n_replications_y):
def replicate_cell(atoms, lattice_constants,
n_replications_x, n_replications_y):
replicated_atoms = []
for i in range(n_replications_x):
for j in range(n_replications_y):
for index, (atom, position) in enumerate(atoms):
new_position = [
position[0] + (lattice_constants[0]) * i, position[1] + (lattice_constants[1])*j, 0.0]
position[0] + (lattice_constants[0]) * i, position[1] + (lattice_constants[1]) * j, 0.0]
replicated_atoms.append((atom, new_position))
return replicated_atoms


def run():
# Parâmetros
unit_cell_file = 'src/simulations/unit_cell.xyz'
Expand All @@ -39,7 +41,7 @@ def run():
OUTPUT_STRUCTURE_FILE = 'src/simulations/pristine_structure.xyz'

write_xyz(OUTPUT_STRUCTURE_FILE, n_replications_x *
n_replications_y * n_atoms, comment, replicated_atoms)
n_replications_y * n_atoms, comment, replicated_atoms)

print('Estrutura "pristine" replicada com sucesso! arquivo salvo em {}'.format(
OUTPUT_STRUCTURE_FILE))
37 changes: 22 additions & 15 deletions src/utils/n1_crack_utils.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@


def y_center_crack(y_index, atom, n_replications_y, crack_size, atom_index, new_position):
floor = int(n_replications_y//2 - ((crack_size - 1)/2))
ceiling = int(n_replications_y//2 + ((crack_size - 1)/2))
if y_index in range(floor, ceiling+1):
def y_center_crack(y_index, atom, n_replications_y,
crack_size, atom_index, new_position):
floor = int(n_replications_y // 2 - ((crack_size - 1) / 2))
ceiling = int(n_replications_y // 2 + ((crack_size - 1) / 2))
if y_index in range(floor, ceiling + 1):
atom = 'H'
if (y_index == floor and atom_index in [0, 1, 2, 3, 4, 8, 9]) or (y_index == ceiling and atom_index in [3, 4, 5, 6, 7, 8, 9]):
if (y_index == floor and atom_index in [0, 1, 2, 3, 4, 8, 9]) or (
y_index == ceiling and atom_index in [3, 4, 5, 6, 7, 8, 9]):
return [atom, new_position]
elif atom_index in [3, 4, 8, 9]:
return [atom, new_position]
else:
return [atom, new_position]

def x_center_crack(x_index, atom, n_replications_x, crack_size, atom_index, new_position):
floor = int(n_replications_x//2 - ((crack_size - 1)/2))
ceiling = int(n_replications_x//2 + ((crack_size - 1)/2))
if x_index in range(floor, ceiling+1):


def x_center_crack(x_index, atom, n_replications_x,
crack_size, atom_index, new_position):
floor = int(n_replications_x // 2 - ((crack_size - 1) / 2))
ceiling = int(n_replications_x // 2 + ((crack_size - 1) / 2))
if x_index in range(floor, ceiling + 1):
atom = 'H'
if (x_index == floor and atom_index in [0, 1, 2, 8, 9,5,6,7,8,9]) or (x_index == ceiling and atom_index in [0,1,2,3,4,5,6,7]):
if (x_index == floor and atom_index in [0, 1, 2, 8, 9, 5, 6, 7, 8, 9]) or (
x_index == ceiling and atom_index in [0, 1, 2, 3, 4, 5, 6, 7]):
return [atom, new_position]
elif atom_index in [0,1,2,5,6,7]:
elif atom_index in [0, 1, 2, 5, 6, 7]:
return [atom, new_position]
else:
return [atom, new_position]

def edge_center_crack(y_index, atom, n_replications_y, crack_size, atom_index, new_position):

def edge_center_crack(y_index, atom, n_replications_y,
crack_size, atom_index, new_position):
ceiling = crack_size
if y_index in range(ceiling+1):
if y_index in range(ceiling + 1):
atom = 'H'
if (y_index == ceiling and atom_index in [3, 4, 5, 6, 7, 8, 9]):
return [atom, new_position]
elif atom_index in [3, 4, 8, 9]:
return [atom, new_position]
else:
return [atom, new_position]
return [atom, new_position]
Loading

0 comments on commit 6a416b1

Please sign in to comment.