Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create formatter.yml #230

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/formatter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: formatter

on:
pull_request:
branches: [ master ]

concurrency: # only allow the most recent workflow to execute
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env: # environment variables
julia_version: '1.8.2' # julia version to use on all runners (except cross-platform-julia)

jobs:
formatting:
runs-on: ubuntu-latest
steps:
- uses: mdecoleman/[email protected]
id: vars
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: julia-actions/setup-julia@latest
with:
version: ${{ env.julia_version }}

- uses: actions/checkout@main

- name: Install JuliaFormatter
run: julia -e 'using Pkg; Pkg.add("JuliaFormatter")'

- name: Run JuliaFormatter
run: |
julia -e '
using JuliaFormatter;
format(
".",
verbose=true,
always_for_in=true,
whitespace_typedefs=true,
whitespace_ops_in_indices=true,
remove_extra_newlines=true,
short_to_long_function_def=true,
long_to_short_function_def=true,
always_use_return=true,
whitespace_in_kwargs=false,
format_docstrings=true,
conditional_to_if=true,
normalize_line_endings="unix",
trailing_comma=false,
separate_kwargs_with_semicolon=true,
format_markdown=true
)'

- name: Formatting Check
run: |
julia -e '
out = Cmd(`git diff --name-only`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
end'

- if: ${{ failure() }}
id: cpr
name: Formatting PR
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: ${{ steps.vars.outputs.branch }}
commit-message: JuliaFormatter Action Bot
title: 'Automatic JuliaFormatter.jl run'
branch: auto-juliaformatter-pr
delete-branch: true
labels: formatting, automated pr, no changelog

- if: ${{ failure() }}
name: comment on PR
uses: thollander/actions-comment-pull-request@v1
with:
message: 'Code formatting requirements not met. See PR #${{ steps.cpr.outputs.pull-request-number }}'
pr_number: ${{ github.event.issue.number }}
comment_includes: "Code formatting requirements not met. See PR #"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![PorousMaterials.jl](PMlogo.png)

| **Documentation** | **DOI** | **Build Status** | **Test Coverage** |
|:---:|:---:|:---:|:---:|
| **Documentation** | **DOI** | **Build Status** | **Test Coverage** |
|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| [![](https://img.shields.io/badge/docs-dev-blue.svg)](https://simonensemble.github.io/PorousMaterials.jl/dev) [![](https://img.shields.io/badge/docs-latest-blue.svg)](https://simonensemble.github.io/PorousMaterials.jl/stable) | [![DOI](https://zenodo.org/badge/102691401.svg)](https://zenodo.org/badge/latestdoi/102691401) | [![Build](https://github.com/SimonEnsemble/PorousMaterials.jl/actions/workflows/ci_testing.yml/badge.svg)](https://github.com/SimonEnsemble/PorousMaterials.jl/actions/workflows/ci_testing.yml) [![Docs](https://github.com/SimonEnsemble/PorousMaterials.jl/actions/workflows/doc_deployment.yml/badge.svg)](https://github.com/SimonEnsemble/PorousMaterials.jl/actions/workflows/doc_deployment.yml) [![Weekly](https://github.com/SimonEnsemble/PorousMaterials.jl/actions/workflows/weekly.yml/badge.svg)](https://github.com/SimonEnsemble/PorousMaterials.jl/actions/workflows/weekly.yml) | [![codecov](https://codecov.io/gh/SimonEnsemble/PorousMaterials.jl/branch/master/graph/badge.svg?token=PWsgNnxfZI)](https://codecov.io/gh/SimonEnsemble/PorousMaterials.jl) [![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) |

A pure-[Julia](https://julialang.org/) package for classical molecular modeling of adsorption in porous crystals such as metal-organic frameworks (MOFs).
12 changes: 7 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
notes:
- all documentation files are in `docs/src`
- `make.jl` automatically pulls doc strings from code in `src`

to deploy locally:
- run `julia make.jl` from `docs` directory.
- open `build/index.html` in your browswer
- all documentation files are in `docs/src`
- `make.jl` automatically pulls doc strings from code in `src`

to deploy locally:

- run `julia make.jl` from `docs` directory.
- open `build/index.html` in your browswer
44 changes: 22 additions & 22 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
using Documenter
using PorousMaterials

makedocs(
root = joinpath(dirname(pathof(PorousMaterials)), "..", "docs"),
modules = [PorousMaterials],
sitename = "PorousMaterials.jl",
clean = true,
pages = [
"PorousMaterials" => "index.md",
"paths" => "paths.md",
"matter" => "matter.md",
"boxes" => "box.md",
"crystals" => "crystal.md",
"molecules" => "molecule.md",
"computing distances" => "distance.md",
"forcefields" => "force_field.md",
"equations of state" => "eos.md",
"Henry coefficients" => "henry.md",
"grand-canonical Monte Carlo simulations" => "gcmc.md",
"energy minimum" => "energy_min.md",
"grids" => "grid.md"
],
format = Documenter.HTML(assets = ["assets/flux.css"])
makedocs(;
root=joinpath(dirname(pathof(PorousMaterials)), "..", "docs"),
modules=[PorousMaterials],
sitename="PorousMaterials.jl",
clean=true,
pages=[
"PorousMaterials" => "index.md",
"paths" => "paths.md",
"matter" => "matter.md",
"boxes" => "box.md",
"crystals" => "crystal.md",
"molecules" => "molecule.md",
"computing distances" => "distance.md",
"forcefields" => "force_field.md",
"equations of state" => "eos.md",
"Henry coefficients" => "henry.md",
"grand-canonical Monte Carlo simulations" => "gcmc.md",
"energy minimum" => "energy_min.md",
"grids" => "grid.md"
],
format=Documenter.HTML(; assets=["assets/flux.css"])
)

deploydocs(repo="github.com/SimonEnsemble/PorousMaterials.jl.git")
deploydocs(; repo="github.com/SimonEnsemble/PorousMaterials.jl.git")
25 changes: 17 additions & 8 deletions docs/src/box.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ A `Box` is most conveniently constructed from its basic spatial data (`a` `b` `c
a = 26.13173 # Å
b = 26.13173
c = 6.722028
α = π/2 # radians
β = π/2
γ = 2*π/3
α = π / 2 # radians
β = π / 2
γ = 2 * π / 3
box = Box(a, b, c, α, β, γ)

# output

Bravais unit cell of a crystal.
Unit cell angles α = 90.000000 deg. β = 90.000000 deg. γ = 120.000000 deg.
Unit cell dimensions a = 26.131730 Å. b = 26.131730 Å, c = 6.722028 Å
Expand All @@ -35,26 +37,31 @@ Bravais unit cell of a crystal.

A `Box` may also be defined by providing only the `Frac`tional-to-`Cart`esian conversion
matrix:

```jldoctest box
box = Box([26.1317 -13.0659 0; 0 22.6307 0; 0 0 6.72203])

# output

Bravais unit cell of a crystal.
Unit cell angles α = 90.000000 deg. β = 90.000000 deg. γ = 120.000113 deg.
Unit cell dimensions a = 26.131700 Å. b = 26.131711 Å, c = 6.722030 Å
Volume of unit cell: 3975.265115 ų
```

To quickly get a simple unit-cubic `Box`, use the `unit_cube` function.

```jldoctest
unit_cube()

# output

Bravais unit cell of a crystal.
Unit cell angles α = 90.000000 deg. β = 90.000000 deg. γ = 90.000000 deg.
Unit cell dimensions a = 1.000000 Å. b = 1.000000 Å, c = 1.000000 Å
Volume of unit cell: 1.000000 ų
```


## transforming coordinates

Conversions are provided for switching between `Frac`tional and `Cart`esian `Coords`
Expand All @@ -63,38 +70,40 @@ using the `Box` (works for `Atoms` and `Charges`, too)
```jldoctest box
xtal = Crystal("SBMOF-1.cif")
Cart(xtal.atoms.coords, xtal.box)

# output

Cart([4.594867082350715 -0.952720283971488 … 0.8392490029633858 -1.5321086078257065; 1.4395486200000005 4.2228986200000005 … 1.4289162230000012 4.212266223; 5.89964228469024 5.359217037237699 … 17.537474811394276 16.239103154389543])
```


## replicating a box

For simulations in larger volumes than a single crystallograhic unit cell, the
`Box` may be replicated along each or any of the three crystallographic axes.

```jldoctest box
replicated_box = replicate(box, (2,2,2))
replicated_box = replicate(box, (2, 2, 2))

# output

Bravais unit cell of a crystal.
Unit cell angles α = 90.000000 deg. β = 90.000000 deg. γ = 120.000113 deg.
Unit cell dimensions a = 52.263400 Å. b = 52.263422 Å, c = 13.444060 Å
Volume of unit cell: 31802.120923 ų
```


## exporting a box

For visualization of the unit cell boundaries, the `Box` may be written out to a
`.vtk` file for use in [Visit](https://wci.llnl.gov/simulation/computer-codes/visit/)

```jldoctest box
write_vtk(box, "box.vtk")

# output

```


# detailed docs

```@docs
Expand Down
50 changes: 27 additions & 23 deletions docs/src/crystal.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ xtal.box # The unit cell information
xtal.atoms # The atom coordinates (in fractional space) and the atom identities
xtal.charges # The charge magnitude and coordinates (in fractional space)
xtal.bonds # Bonding information in the structure. By default this is an empty graph,
# but use `read_bonds_from_file=true` argument in `Crystal` to read from crystal structure file
# but use `read_bonds_from_file=true` argument in `Crystal` to read from crystal structure file
xtal.symmetry # Symmetry information of the crystal. By default converts the symmetry to P1 symmetry.
# Use `convert_to_p1=false` argument in `Crystal` to keep original symmetry
# Use `convert_to_p1=false` argument in `Crystal` to keep original symmetry

# output

Xtals.SymmetryInfo(["x"; "y"; "z";;], "P1", true)
```

Expand All @@ -37,6 +39,7 @@ It is important to use this function prior to GCMC or Henry coefficient calculat
strip_numbers_from_atom_labels!(xtal)

# output

```

## converting the coordinates to cartesian space
Expand All @@ -47,7 +50,9 @@ that can be done by using the unit cell information of the crystal.
```jldoctest crystal
xtal.atoms.coords.xf # array of fractional coordinates
cart_coords = xtal.box.f_to_c * xtal.atoms.coords.xf # array of cartesian coordinates

# output

3×120 Matrix{Float64}:
4.59487 -0.95272 2.68943 8.23701 … 8.8164 0.839249 -1.53211
1.43955 4.2229 4.12715 1.3438 1.35443 1.42892 4.21227
Expand All @@ -59,23 +64,14 @@ cart_coords = xtal.box.f_to_c * xtal.atoms.coords.xf # array of cartesian coo
For many simulations, one needs to replicate the unit cell multiple times to create a bigger super cell.

```jldoctest crystal
super_xtal = replicate(xtal, (2,2,2)) # Replicates the original unit cell once in each dimension
super_xtal = replicate(xtal, (2, 2, 2)) # Replicates the original unit cell once in each dimension

# output
Name: SBMOF-1.cif
Bravais unit cell of a crystal.
Unit cell angles α = 90.000000 deg. β = 100.897000 deg. γ = 90.000000 deg.
Unit cell dimensions a = 23.238600 Å. b = 11.133400 Å, c = 45.862400 Å
Volume of unit cell: 11651.776815 ų

# atoms = 960
# charges = 960
chemical formula: Ca₃₂C₄₄₈H₂₅₆O₁₉₂S₃₂
space Group: P1
symmetry Operations:
'x, y, z'
bonding graph:
# vertices = 960
# edges = 0

Crystal(Ca₃₂C₄₄₈H₂₅₆O₁₉₂S₃₂, periodic = TTT):
bounding_box : [ 23.2386 0 0;
6.81724e-16 11.1334 0;
-8.67001 3.33915e-15 45.0354]u"Å"
```

## finding other properties
Expand All @@ -84,7 +80,9 @@ Bravais unit cell of a crystal.
rho = crystal_density(xtal) # Crystal density of the crystal in kg/m^2
mw = molecular_weight(xtal) # The molecular weight of the unit cell in amu
formula = chemical_formula(xtal) # The irreducible chemical formula of the crystal

# output

"Ca₄C₅₆H₃₂O₂₄S₄"
```

Expand All @@ -95,11 +93,17 @@ If the crystal structure file does not contains partial charges, we provide meth
```julia
species_to_charges = Dict(:Ca => 2.0, :C => 1.0, :H => -1.0) # This method assigns a static charge to atom species
charged_xtal = assign_charges(xtal, species_to_charges, 1e-5) # This function creates a new charged `Crystal` object.
# The function checks for charge neutrality with a tolerance of 1e-5
# The function checks for charge neutrality with a tolerance of 1e-5
new_charges = Charges([2.0, 1.0, -1.0, -1.0, ...], xtal.atoms.coords)
other_charged_xtal = Crystal(xtal.name, xtal.box, xtal.atoms, # Here we create a new `Charges` object using an array of new charges.
new_charges, xtal.bonds, xtal.symmetry) # The number of charges in the array has to be equal to the number of atoms
# and finally a new `Crystal` object is manually created
other_charged_xtal = Crystal(
xtal.name,
xtal.box,
xtal.atoms, # Here we create a new `Charges` object using an array of new charges.
new_charges,
xtal.bonds,
xtal.symmetry
) # The number of charges in the array has to be equal to the number of atoms
# and finally a new `Crystal` object is manually created
```

## writing crystal files
Expand All @@ -109,11 +113,11 @@ We provide methods to write both `.xyz` and `.cif` files
```jldoctest crystal; output=false
write_cif(xtal, "my_new_cif_file.cif") # Stored in the current directory
write_xyz(xtal, "my_new_xyz_file.xyz") # stored in the current directory

# output

```


# detailed docs

```@docs
Expand Down
6 changes: 6 additions & 0 deletions docs/src/distance.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ within a given `box`.
```jldoctest distance
xtal = Crystal("SBMOF-1.cif")
distance(xtal.atoms.coords, xtal.box, 1, 10, false) # Cartesian distance within the unit cell

# output

4.962373067546231
```

Expand All @@ -23,15 +25,19 @@ across the periodic boundaries of the `box`.

```jldoctest distance
distance(xtal.atoms.coords, xtal.box, 1, 10, true) # Cartesian distance accounting for periodic boundary

# output

4.143597209982431
```

`distance` also works on `Atoms` and `Charges`.

```jldoctest distance
distance(xtal.atoms, xtal.box, 3, 5, true)

# output

10.244292605252747
```

Expand Down
Loading
Loading