Skip to content

Commit

Permalink
Merge pull request #124 from pyiron/run_black
Browse files Browse the repository at this point in the history
Run black everywhere
  • Loading branch information
samwaseda authored Jan 25, 2025
2 parents bb4a4c8 + 0610796 commit e1ac3c1
Show file tree
Hide file tree
Showing 36 changed files with 987 additions and 590 deletions.
7 changes: 6 additions & 1 deletion pyiron_nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@

__version__ = get_versions()["version"]

from pyiron_nodes import atomistic, databases, math, plotting #, continuum_fem, large_scale_atomistic
from pyiron_nodes import (
atomistic,
databases,
math,
plotting,
) # , continuum_fem, large_scale_atomistic
49 changes: 24 additions & 25 deletions pyiron_nodes/atomistic/engine/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def CalcMinimize(calculator_input: Optional[InputCalcMinimize | dict] = None):
@as_function_node("calculator")
def CalcMD(calculator_input: Optional[InputCalcMD.dataclass] = None):
from dataclasses import asdict

if calculator_input is None:
calculator_input = InputCalcMD.dataclass()

Expand All @@ -72,7 +73,13 @@ def CalcMD(calculator_input: Optional[InputCalcMD.dataclass] = None):


@as_function_node("path")
def InitLammps(structure, potential: str, calculator, working_directory: str, create_dir: bool = True):
def InitLammps(
structure,
potential: str,
calculator,
working_directory: str,
create_dir: bool = True,
):
import os
from pyiron_atomistics.lammps.potential import LammpsPotential, LammpsPotentialFile

Expand Down Expand Up @@ -127,10 +134,10 @@ class ShellOutput:

@as_function_node("output", "dump", "log")
def Shell(
working_directory: str,
command: str = "lmp",
environment: Optional[dict] = None,
arguments: Optional[list] = None,
working_directory: str,
command: str = "lmp",
environment: Optional[dict] = None,
arguments: Optional[list] = None,
):
arguments = ["-in", "control.inp"] if arguments is None else arguments
# -> (ShellOutput, FileObject, FileObject): TODO: fails -> why
Expand Down Expand Up @@ -174,9 +181,9 @@ class GenericOutput:

@as_function_node
def Collect(
out_dump,
out_log,
calc_mode: str | LammpsControl | InputCalcMinimize | InputCalcMD | InputCalcStatic,
out_dump,
out_log,
calc_mode: str | LammpsControl | InputCalcMinimize | InputCalcMD | InputCalcStatic,
):
import numpy as np

Expand Down Expand Up @@ -264,22 +271,18 @@ def GetEnergyPot(generic, i_start: int = 0, i_end: int = -1):

@as_macro_node("generic")
def Code(
wf,
structure: Atoms,
calculator=InputCalcStatic(), # TODO: Don't use mutable defaults
potential: Optional[str] = None,
working_dir: str = "test2",
wf,
structure: Atoms,
calculator=InputCalcStatic(), # TODO: Don't use mutable defaults
potential: Optional[str] = None,
working_dir: str = "test2",
):
# from pyiron_contrib.tinybase.shell import ExecutablePathResolver

# print("Lammps: ", structure)
wf.Potential = Potential(
structure=structure, name=potential
)
wf.Potential = Potential(structure=structure, name=potential)

wf.ListPotentials = ListPotentials(
structure=structure
)
wf.ListPotentials = ListPotentials(structure=structure)

wf.calc = Calc(calculator)

Expand All @@ -295,12 +298,8 @@ def Code(
working_directory=wf.InitLammps,
)

wf.ParseLogFile = ParseLogFile(
log_file=wf.Shell.outputs.log
)
wf.ParseDumpFile = ParseDumpFile(
dump_file=wf.Shell.outputs.dump
)
wf.ParseLogFile = ParseLogFile(log_file=wf.Shell.outputs.log)
wf.ParseDumpFile = ParseDumpFile(dump_file=wf.Shell.outputs.dump)
wf.Collect = Collect(
out_dump=wf.ParseDumpFile.outputs.dump,
out_log=wf.ParseLogFile.outputs.log,
Expand Down
46 changes: 23 additions & 23 deletions pyiron_nodes/atomistic/property/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ class OutputElasticAnalysis:

@as_macro_node
def ElasticConstants(
self,
structure,
engine: Optional[OutputEngine] = None,
# But OutputEngine had better be holding a ase.calculators.calculator.BaseCalculator
# There is too much misdirection for me to track everything right now, but I think
# some of the "generic" stuff doesn't work
parameters: Optional[InputElasticTensor.dataclass] = InputElasticTensor.dataclass(),
# contains the default values
self,
structure,
engine: Optional[OutputEngine] = None,
# But OutputEngine had better be holding a ase.calculators.calculator.BaseCalculator
# There is too much misdirection for me to track everything right now, but I think
# some of the "generic" stuff doesn't work
parameters: Optional[InputElasticTensor.dataclass] = InputElasticTensor.dataclass(),
# contains the default values
) -> OutputElasticAnalysis:
self.symmetry_analysis = SymmetryAnalysis(structure, parameters=parameters)

Expand Down Expand Up @@ -119,7 +119,7 @@ def ExtractFinalEnergy(df):

@as_function_node
def SymmetryAnalysis(
structure, parameters: Optional[InputElasticTensor.dataclass]
structure, parameters: Optional[InputElasticTensor.dataclass]
) -> OutputElasticSymmetryAnalysis:
parameters = InputElasticTensor.dataclass() if parameters is None else parameters
out = OutputElasticSymmetryAnalysis(structure)
Expand All @@ -137,9 +137,9 @@ def SymmetryAnalysis(

@as_function_node("structures")
def GenerateStructures(
structure,
analysis: OutputElasticSymmetryAnalysis,
parameters: Optional[InputElasticTensor.dataclass] = None,
structure,
analysis: OutputElasticSymmetryAnalysis,
parameters: Optional[InputElasticTensor.dataclass] = None,
):
structure_dict = {}

Expand Down Expand Up @@ -201,9 +201,9 @@ def GenerateStructures(

@as_function_node("structures")
def AnalyseStructures(
data_df: DataStructureContainer,
analysis: OutputElasticSymmetryAnalysis,
parameters: Optional[InputElasticTensor.dataclass] = None,
data_df: DataStructureContainer,
analysis: OutputElasticSymmetryAnalysis,
parameters: Optional[InputElasticTensor.dataclass] = None,
) -> OutputElasticAnalysis:
zero_strain_job_name = "s_e_0"

Expand Down Expand Up @@ -236,10 +236,10 @@ def calculate_modulus(out: OutputElasticAnalysis):

BV = (C[0, 0] + C[1, 1] + C[2, 2] + 2 * (C[0, 1] + C[0, 2] + C[1, 2])) / 9
GV = (
(C[0, 0] + C[1, 1] + C[2, 2])
- (C[0, 1] + C[0, 2] + C[1, 2])
+ 3 * (C[3, 3] + C[4, 4] + C[5, 5])
) / 15
(C[0, 0] + C[1, 1] + C[2, 2])
- (C[0, 1] + C[0, 2] + C[1, 2])
+ 3 * (C[3, 3] + C[4, 4] + C[5, 5])
) / 15
EV = (9 * BV * GV) / (3 * BV + GV)
nuV = (1.5 * BV - GV) / (3 * BV + GV)
out.BV = BV
Expand All @@ -252,9 +252,9 @@ def calculate_modulus(out: OutputElasticAnalysis):

BR = 1 / (S[0, 0] + S[1, 1] + S[2, 2] + 2 * (S[0, 1] + S[0, 2] + S[1, 2]))
GR = 15 / (
4 * (S[0, 0] + S[1, 1] + S[2, 2])
- 4 * (S[0, 1] + S[0, 2] + S[1, 2])
+ 3 * (S[3, 3] + S[4, 4] + S[5, 5])
4 * (S[0, 0] + S[1, 1] + S[2, 2])
- 4 * (S[0, 1] + S[0, 2] + S[1, 2])
+ 3 * (S[3, 3] + S[4, 4] + S[5, 5])
)
ER = (9 * BR * GR) / (3 * BR + GR)
nuR = (1.5 * BR - GR) / (3 * BR + GR)
Expand Down Expand Up @@ -306,7 +306,7 @@ def fit_elastic_matrix(out: OutputElasticAnalysis, fit_order, v0, LC):
C[j, i] = C[i, j]

CONV = (
1e21 / scipy.constants.physical_constants["joule-electron volt relationship"][0]
1e21 / scipy.constants.physical_constants["joule-electron volt relationship"][0]
) # From eV/Ang^3 to GPa

C *= CONV
Expand Down
1 change: 1 addition & 0 deletions pyiron_nodes/atomistic/structure/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def HighIndexSurface(
slab.set_pbc(True)
return ase_to_pyiron(slab)


@as_macro_node("structure")
def CubicBulkCell(
wf, element: str, cell_size: int = 1, vacancy_index: Optional[int] = None
Expand Down
24 changes: 10 additions & 14 deletions pyiron_nodes/continuum_fem/boundary_conditions/scalar_geometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
from typing import Callable
import numpy as np


@as_function_node("bc")
def ScalarDirichlet1D(
function_space,
bc_function: str,
value: Optional[float|int]
):
def ScalarDirichlet1D(function_space, bc_function: str, value: Optional[float | int]):
from dolfinx import fem, default_scalar_type

lazy_evaluation = lambda x: eval(bc_function)
Expand All @@ -17,26 +14,28 @@ def ScalarDirichlet1D(
bc = fem.dirichletbc(default_scalar_type(value), boundary_dofs, function_space)
return bc


@as_function_node("bc")
def ScalarDirichlet3D(
function_space,
bc_function: str,
value_x: Optional[float|int],
value_y: Optional[float|int],
value_z: Optional[float|int]
value_x: Optional[float | int],
value_y: Optional[float | int],
value_z: Optional[float | int],
):

from dolfinx import fem, default_scalar_type

lazy_evaluation = lambda x: eval(bc_function)
result = lazy_evaluation
boundary_dofs = fem.locate_dofs_geometrical(function_space, result)
u_D = np.array([value_x, value_y, value_z], dtype=default_scalar_type)
bc = fem.dirichletbc(u_D, boundary_dofs, function_space)
return bc


@as_function_node("bcs_array")
def CollectBcs(bc1 = None, bc2 = None, bc3 = None, bc4 = None, bc5 = None, bc6 = None):
def CollectBcs(bc1=None, bc2=None, bc3=None, bc4=None, bc5=None, bc6=None):

bcs = []
if bc1 is not None:
Expand All @@ -58,6 +57,3 @@ def CollectBcs(bc1 = None, bc2 = None, bc3 = None, bc4 = None, bc5 = None, bc6 =
bcs.append(bc6)

return bcs



4 changes: 1 addition & 3 deletions pyiron_nodes/continuum_fem/custom_nodes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from pyiron_nodes.continuum_fem.custom_nodes import (
custom_plots
)
from pyiron_nodes.continuum_fem.custom_nodes import custom_plots
23 changes: 14 additions & 9 deletions pyiron_nodes/continuum_fem/custom_nodes/custom_plots.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from pyiron_workflow import as_function_node
from typing import Optional


@as_function_node("load_deflection_plot")
def PoissonLoadDeflectionPlot(
domain,
solution_vector,
load
):
def PoissonLoadDeflectionPlot(domain, solution_vector, load):
from dolfinx import fem
import numpy as np
import matplotlib.pyplot as plt
Expand All @@ -28,19 +25,27 @@ def PoissonLoadDeflectionPlot(
# Find cells whose bounding-box collide with the the points
cell_candidates = geometry.compute_collisions_points(bb_tree, points.T)
# Choose one of the cells that contains the point
colliding_cells = geometry.compute_colliding_cells(domain, cell_candidates, points.T)
colliding_cells = geometry.compute_colliding_cells(
domain, cell_candidates, points.T
)
for i, point in enumerate(points.T):
if len(colliding_cells.links(i)) > 0:
points_on_proc.append(point)
cells.append(colliding_cells.links(i)[0])

points_on_proc = np.array(points_on_proc, dtype=np.float64)
u_values = solution_vector.eval(points_on_proc, cells)
p_values = pressure.eval(points_on_proc, cells)
fig = plt.figure()
plt.plot(points_on_proc[:, 1], 50 * u_values, "k", linewidth=2, label="Deflection ($\\times 50$)")
plt.plot(
points_on_proc[:, 1],
50 * u_values,
"k",
linewidth=2,
label="Deflection ($\\times 50$)",
)
plt.plot(points_on_proc[:, 1], p_values, "b--", linewidth=2, label="Load")
plt.grid(True)
plt.xlabel("y")
plt.legend()
return plt.show()
return plt.show()
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pyiron_workflow import as_function_node
from typing import Optional


@as_function_node("function_space")
def FunctionSpace(
domain,
Expand All @@ -12,6 +13,7 @@ def FunctionSpace(
V = fem.functionspace(domain, (el_type, el_order))
return V


@as_function_node("function_space")
def VectorFunctionSpace(
domain,
Expand All @@ -21,4 +23,4 @@ def VectorFunctionSpace(
from dolfinx import fem

V = fem.functionspace(domain, (el_type, el_order, (3,)))
return V
return V
Loading

0 comments on commit e1ac3c1

Please sign in to comment.