Skip to content

Commit

Permalink
formatting (#178)
Browse files Browse the repository at this point in the history
* formatting

* JuliaFormatter Action Bot (#179)

Co-authored-by: eahenle <[email protected]>

* JuliaFormatter Action Bot (#180)

Co-authored-by: eahenle <[email protected]>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: eahenle <[email protected]>
  • Loading branch information
3 people authored Oct 12, 2022
1 parent 9adbe0d commit f99aa60
Show file tree
Hide file tree
Showing 31 changed files with 1,802 additions and 1,218 deletions.
6 changes: 3 additions & 3 deletions .github/workflow_extras/write_load_combos.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Combinatorics
open("load_combos.sh", "w") do f
for (a,b,c,d) in permutations(ARGS)
for (a, b, c, d) in permutations(ARGS)
write(f, "julia --project -e 'using $a; using $b; using $c; using $d' && \\\n")
end
write(f, "echo -e \\\\nDone!\n")
end
return write(f, "echo -e \\\\nDone!\n")
end
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![Xtals.jl](logo.jpg)

| **Documentation** | **Build Status** | **Test Coverage** |
|:---:|:---:|:---:|
| **Documentation** | **Build Status** | **Test Coverage** |
|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| [![](https://img.shields.io/badge/docs-latest-blue.svg)](https://SimonEnsemble.github.io/Xtals.jl/stable) [![](https://img.shields.io/badge/docs-dev-blue.svg)](https://SimonEnsemble.github.io/Xtals.jl/dev) | [![CI](https://github.com/SimonEnsemble/Xtals.jl/actions/workflows/CI_Build.yml/badge.svg)](https://github.com/SimonEnsemble/Xtals.jl/actions/workflows/CI_Build.yml) [![Docs](https://github.com/SimonEnsemble/Xtals.jl/actions/workflows/doc_deployment.yml/badge.svg)](https://github.com/SimonEnsemble/Xtals.jl/actions/workflows/doc_deployment.yml) [![weekly](https://github.com/SimonEnsemble/Xtals.jl/actions/workflows/weekly.yml/badge.svg)](https://github.com/SimonEnsemble/Xtals.jl/actions/workflows/weekly.yml) | [![codecov](https://codecov.io/gh/SimonEnsemble/Xtals.jl/branch/master/graph/badge.svg?token=QM6XZ3KAW1)](https://codecov.io/gh/SimonEnsemble/Xtals.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 importing, manipulating, and working with crystal structures, such as metal-organic frameworks (MOFs).
36 changes: 18 additions & 18 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
using Documenter
using Xtals, XtalsPyTools

makedocs(
root = joinpath(dirname(pathof(Xtals)), "..", "docs"),
modules = [Xtals, XtalsPyTools],
sitename = "Xtals.jl",
clean = true,
pages = [
"Xtals" => "index.md",
"globals" => "globals.md",
"matter" => "matter.md",
"boxes" => "box.md",
"crystals" => "crystal.md",
"computing distances" => "distance.md",
"bonding" => "bonds.md",
"visualization" => "visualization.md",
"XtalsPyTools" => "pytools.md"
],
format = Documenter.HTML(assets = ["assets/flux.css"])
makedocs(;
root=joinpath(dirname(pathof(Xtals)), "..", "docs"),
modules=[Xtals, XtalsPyTools],
sitename="Xtals.jl",
clean=true,
pages=[
"Xtals" => "index.md",
"globals" => "globals.md",
"matter" => "matter.md",
"boxes" => "box.md",
"crystals" => "crystal.md",
"computing distances" => "distance.md",
"bonding" => "bonds.md",
"visualization" => "visualization.md",
"XtalsPyTools" => "pytools.md"
],
format=Documenter.HTML(; assets=["assets/flux.css"])
)

deploydocs(repo = "github.com/SimonEnsemble/Xtals.jl.git")
deploydocs(; repo="github.com/SimonEnsemble/Xtals.jl.git")
44 changes: 31 additions & 13 deletions docs/src/bonds.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,48 @@ The nodes of the graph correspond to the [`Crystal`](@ref)'s [`Atoms`](@ref), an

## Bonding Rules

`Xtals` uses an array of [`BondingRule`](@ref) structs stored in `rc` for deciding if two [`Atoms`](@ref) are an appropriate distance to be chemically bonded.
The default rules are based on the [Cordero covalent radii](https://doi.org/10.1039/B801115J), modified based on the work of [Thomas Manz](https://doi.org/10.1039/c9ra07327b).
`Xtals` uses an array of [`BondingRule`](@ref) structs stored in `rc` for deciding if two [`Atoms`](@ref) are an appropriate distance to be chemically bonded.
The default rules are based on the [Cordero covalent radii](https://doi.org/10.1039/B801115J), modified based on the work of [Thomas Manz](https://doi.org/10.1039/c9ra07327b).
Each [`BondingRule`](@ref) is composed of two chemical species symbols and a floating point value, the maximum distance for inferring a bond between the indicated species.

```jldoctest; output=false
BondingRule(:C, :C, 1.77)
# output
BondingRule(:C, :C, 1.77)
```

The global bonding rules may be augmented with [`add_bonding_rules`](@ref) or written to/read from disk with [`write_bonding_rules`](@ref) and [`read_bonding_rules`](@ref).
The default rules are determined from `rc[:covalent_radii]` at module load, but *are not recalculated upon changes to the covalent radii.*
The global bonding rules may be augmented with [`add_bonding_rules`](@ref) or written to/read from disk with [`write_bonding_rules`](@ref) and [`read_bonding_rules`](@ref).
The default rules are determined from `rc[:covalent_radii]` at module load, but *are not recalculated upon changes to the covalent radii.*
If `rc[:covalent_radii]` is altered and new bonding rules should be calculated, the user must do `rc[:bonding_rules] = bondingrules()`.

## Adding Bonds to Crystals

By default, bonding information is not added to a [`Crystal`](@ref).
Bonds may be inferred at the time of loading structure data by using the `infer_bonds` keyword argument.
By default, bonding information is not added to a [`Crystal`](@ref).
Bonds may be inferred at the time of loading structure data by using the `infer_bonds` keyword argument.
See [`Crystal`](@ref) for more details.

```jldoctest bonds
xtal = Crystal("SBMOF-1.cif", infer_bonds=true, periodic_boundaries=true)
xtal = Crystal("SBMOF-1.cif"; infer_bonds=true, periodic_boundaries=true)
xtal.bonds
# output
{120, 144} undirected Int64 metagraph with Float64 weights defined by :weight (default weight 1.0)
```

The first number is the number of nodes, and the second is the number of edges.
The first number is the number of nodes, and the second is the number of edges.
The `:weight` attribute is not used, and can be ignored.

[`remove_bonds!`](@ref) clears the bonding information from a [`Crystal`](@ref):

```jldoctest bonds
remove_bonds!(xtal)
xtal.bonds
# output
{120, 0} undirected Int64 metagraph with Float64 weights defined by :weight (default weight 1.0)
```

Expand All @@ -55,46 +61,54 @@ Use [`infer_bonds!`](@ref) to infer plausible bonds using the global bonding rul
```jldoctest bonds
infer_bonds!(xtal, true)
xtal.bonds
# output
{120, 144} undirected Int64 metagraph with Float64 weights defined by :weight (default weight 1.0)
```

## Bonds from Input File

Some chemical information formats, like `.cif` and `.mol`, can store not only the cartesian coordinates of atoms, but also the graph of bonds between atoms in molecules and crystals.
The `read_bonds_from_file` keyword argument for [`Crystal`](@ref) enables loading these bonds when reading the data.
Some chemical information formats, like `.cif` and `.mol`, can store not only the cartesian coordinates of atoms, but also the graph of bonds between atoms in molecules and crystals.
The `read_bonds_from_file` keyword argument for [`Crystal`](@ref) enables loading these bonds when reading the data.
[`read_mol`](@ref) also returns bond information.

## Bonds for Atoms

In the case that atomic coordinates are loaded from XYZ format, there will be no unit cell information.
In the case that atomic coordinates are loaded from XYZ format, there will be no unit cell information.
To infer bonds between atoms in this case, use the [`infer_bonds`](@ref) function:

```jldoctest bonds
atoms = Cart(xtal.atoms, xtal.box) # get atoms in Cartesian coords
bonds = infer_bonds(atoms) # infer bonding graph
# output
{120, 110} undirected Int64 metagraph with Float64 weights defined by :weight (default weight 1.0)
```

## Bond Distances, Vectors, and Angles

Bonds may be labeled with several additional pieces of information.
Bonds may be labeled with several additional pieces of information.
The first is the center-to-center distance between the bonded atoms, accessible via [`bond_distance`](@ref):

```jldoctest bonds
bond_distance(xtal, 1, 5)
# output
1.5233240952030063
```

The bond distance is automatically added by [`infer_bonds!`](@ref).
The bond distance is automatically added by [`infer_bonds!`](@ref).
Applying [`calculate_bond_vectors!`](@ref) (or passing `calculate_vectors=true` to [`infer_bonds!`](@ref)) labels each edge in the bonding graph with a vector, accessible via [`get_bond_vector`](@ref):

```jldoctest bonds
calculate_bond_vectors!(xtal)
get_bond_vector(xtal, 1, 5)
# output
3-element Vector{Float64}:
-1.2460713575602618
-0.26441824999999985
Expand All @@ -105,7 +119,9 @@ While the bond graph itself is undirected, the vectors returned by [`get_bond_ve

```jldoctest bonds
get_bond_vector(xtal, 5, 1)
# output
3-element Vector{Float64}:
1.2460713575602618
0.26441824999999985
Expand All @@ -117,7 +133,9 @@ To get the angle (in radians) between two bonds, use [`bond_angle`](@ref):

```jldoctest bonds
bond_angle(xtal, 1, 5, 9)
# output
2.089762039489374
```

Expand Down
12 changes: 6 additions & 6 deletions docs/src/box.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ For example, given the unit cell of Co-MOF-74, we can define its [`Box`](@ref):
a = 26.13173 #
b = 26.13173
c = 6.722028
α = π/2 # radians
β = π/2
γ = 2*π/3
α = π / 2 # radians
β = π / 2
γ = 2 * π / 3
box = Box(a, b, c, α, β, γ)
```

Expand All @@ -40,7 +40,6 @@ To quickly get a simple unit-cubic [`Box`](@ref), use the [`unit_cube`](@ref) fu
#└ Volume of unit cell: 1.000000 ų
```


## Transforming Coordinates

Conversions are provided for switching between [`Frac`](@ref)tional and [`Cart`](@ref)esian [`Coords`](@ref) using the [`Box`](@ref) (works for [`Atoms`](@ref) and [`Charges`](@ref), too).
Expand All @@ -53,14 +52,13 @@ Cart(xtal.atoms.coords, xtal.box)
# 1.231811631 0.32198514120000005 … 6.2082409932000004 2.2119953472])
```


## Replicating a Box

For simulations in larger volumes than a single crystallograhic unit cell, the [`Box`](@ref) may be replicated along each or any of the three crystallographic axes.
See [`replicate`](@ref).

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

## Exporting a Box
Expand All @@ -69,7 +67,9 @@ For visualization of the unit cell boundaries, the [`Box`](@ref) may be written

```jldoctest; setup=:(box = Box([26.1317 -13.0659 0; 0 22.6307 0; 0 0 6.72203])), output=false
write_vtk(box, "box.vtk"; verbose=true)
# output
See box.vtk
```

Expand Down
42 changes: 29 additions & 13 deletions docs/src/crystal.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ end

## Reading in a Crystal Structure File

Currently, the crystal structure file reader accepts `.cif` and `.cssr` file formats.
`Xtals.jl` looks for the crystal structure files in `rc[:paths][:crystals]` which is by default `./data/crystals` (relative to `pwd()` at module loading).
Currently, the crystal structure file reader accepts `.cif` and `.cssr` file formats.
`Xtals.jl` looks for the crystal structure files in `rc[:paths][:crystals]` which is by default `./data/crystals` (relative to `pwd()` at module loading).
By typing `rc[:paths][:crystals] = "my_crystal_dir"`, `Xtals.jl` now looks for the crystal structure file in `my_crystal_dir`.
The files can be read as:

Expand All @@ -22,37 +22,43 @@ 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)
```

## Fixing Atom Species Labels

Often, the atoms species are appended by numbers.
Often, the atoms species are appended by numbers.
This messes with the internal workings of `Xtals.jl`.
To circumvent this problem, the function [`strip_numbers_from_atom_labels!`](@ref) removes the appended numbers.
It is important to use this function prior to GCMC or Henry coefficient calculations and bond inference operations.

```jldoctest crystal
xtal = Crystal("IRMOF-1.cif", species_col=["_atom_site_label"])
xtal = Crystal("IRMOF-1.cif"; species_col=["_atom_site_label"])
xtal.atoms.species[1]
# output
:Zn1
```

```jldoctest crystal
strip_numbers_from_atom_labels!(xtal)
xtal.atoms.species[1]
# output
:Zn
```

## Converting the Coordinates to Cartesian Space

The coordinates of the [`Crystal`](@ref)'s [`Atoms`](@ref) are stored in [`Frac`](@ref)tional coordinates.
The coordinates of the [`Crystal`](@ref)'s [`Atoms`](@ref) are stored in [`Frac`](@ref)tional coordinates.
If one needs to analyze the [`Cart`](@ref)esian coordinates of the [`Crystal`](@ref), that can be done by using the unit cell ([`Box`](@ref)) information.

```julia
Expand All @@ -66,9 +72,11 @@ For many simulations, one needs to replicate the unit cell multiple times to cre
This is done with [`replicate`](@ref):

```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
xtal.atoms.n, super_xtal.atoms.n
# output
(424, 3392)
```

Expand All @@ -87,12 +95,20 @@ If the structure file does not contain partial charges, we provide methods to as
```jldoctest crystal; output=false
species_to_charge = Dict(:Zn => 2.0, :C => 0.0, :H => 0.0, :O => -0.61538) # This method assigns a static charge to atom species
charged_xtal = assign_charges(xtal, species_to_charge, 1e-3) # This function creates a new charged `Crystal` object.
# The function checks for charge neutrality with a tolerance of 1e-3
# The function checks for charge neutrality with a tolerance of 1e-3
new_charges = Charges(zeros(xtal.atoms.n), 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
# output
Name: IRMOF-1.cif
Bravais unit cell of a crystal.
Unit cell angles α = 90.000000 deg. β = 90.000000 deg. γ = 90.000000 deg.
Expand All @@ -117,11 +133,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
8 changes: 7 additions & 1 deletion docs/src/distance.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,35 @@ end

# Distances

The distance between two [`Atoms`](@ref) in a [`Crystal`](@ref) is central to many operations within `Xtals.jl`.
The distance between two [`Atoms`](@ref) in a [`Crystal`](@ref) is central to many operations within `Xtals.jl`.
The [`distance`](@ref) function calculates the [`Cart`](@ref)esian displacement between the [`Coords`](@ref) ([`Cart`](@ref) or [`Frac`](@ref)) of two points, `i` and `j`, within a given [`Box`](@ref), in units of Å.

```jldoctest distance
xtal = Crystal("IRMOF-1.cif")
distance(xtal.atoms.coords, xtal.box, 1, 2, false)
# output
18.538930020700434
```

The `apply_pbc` argument allows for calculation of distances across the periodic boundaries of the [`Box`](@ref).

```jldoctest distance
distance(xtal.atoms.coords, xtal.box, 1, 2, true)
# output
15.096469110488975
```

[`distance`](@ref) also works on [`Atoms`](@ref) and [`Charges`](@ref).

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

Expand Down
Loading

0 comments on commit f99aa60

Please sign in to comment.