Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
Updated to newest dataframe
Browse files Browse the repository at this point in the history
Also moved from Lumberjack to MicroLogging because the latter seems
maintained and easier to use.
  • Loading branch information
mdavezac committed Feb 27, 2018
1 parent 44216b8 commit a39da98
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 131 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ julia 0.6
Unitful
DataFrames
CoordinateTransformations
Lumberjack
MicroLogging
NamedTuples
Documenter
DocStringExtensions
8 changes: 5 additions & 3 deletions docs/src/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ Modules = [Crystals.Lattices]
## Output and Logging

Information and errors during calculations are displayed using an internal log provided by
[Lumberjack](https://www.github.com/WestleyArgentum/Lumberjack.jl). By default, only
critical errors result in output. The verbosity can be set manually.
[MicroLogging](https://www.github.com/c42f/MicroLogging.jl). Verbosity can be set manually
with:

```@docs
Crystals.Log.set_log_level
using MicroLogging
using Crystals
configure_logging(Crystals, min_level=:error)
```
3 changes: 1 addition & 2 deletions src/Crystals.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Crystals
using Unitful
using MicroLogging
export @u_str

export Crystal, is_fractional, volume, round!, are_compatible_lattices
Expand All @@ -19,8 +20,6 @@ if Pkg.installed("Unitful") ≤ v"0.0.4"
end
end

include("Logging.jl")

module Constants
const default_tolerance = 1e-8
end
Expand Down
11 changes: 5 additions & 6 deletions src/Gruber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export gruber, niggly
using Crystals.Constants: default_tolerance
using Crystals.Utilities: cell_parameters
using Crystals.Structures: Crystal, volume
using Crystals: Log
using Unitful: unit, ustrip, Quantity
using MicroLogging

function no_opt_change_test(new, last)
const m_new = 16e0 * new;
Expand Down Expand Up @@ -68,7 +68,7 @@ function n4_action(params::Vector, rinv::Matrix; tolerance=default_tolerance)
elseif i == 1 && params[4] > -tolerance
update[1, 1] = -1
elseif i * j * k == -1
Log.error("Internal error")
error("Internal error")
end
end
rinv[:, :] = rinv * update
Expand Down Expand Up @@ -131,8 +131,8 @@ the `niggly` algorithm.
function gruber{T <: Number}(cell::Matrix{T};
tolerance::Real=default_tolerance, itermax::Integer=50,
max_no_change::Integer=10)
size(cell, 1) == size(cell, 2) || Log.error("Matrix not rectangular")
volume(cell) > tolerance || Log.error("Singular matrix");
size(cell, 1) == size(cell, 2) || error("Matrix not rectangular")
volume(cell) > tolerance || error("Singular matrix")
if itermax 0
itermax = typemax(itermax)
end
Expand Down Expand Up @@ -186,8 +186,7 @@ function gruber{T <: Number}(cell::Matrix{T};
) || break
n8_action(params, rinv)
end
iteration == itermax &&
Log.error("Reached end of iteration without converging")
iteration == itermax && error("Reached end of iteration without converging")
cell * rinv
end

Expand Down
48 changes: 0 additions & 48 deletions src/Logging.jl

This file was deleted.

35 changes: 17 additions & 18 deletions src/SpaceGroup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ using Crystals.Structures: Crystal, volume
using Crystals.Gruber: gruber
using Crystals.Utilities: into_voronoi, is_periodic, into_cell, is_unitful, to_fractional
using Crystals.Utilities: to_cartesian, to_same_kind
using Crystals: Log
using MicroLogging
using Unitful: ustrip, Quantity, unit
using CoordinateTransformations: AffineMap
using DataFrames: isna, by, nrow, eachrow, DataFrame, AbstractDataFrame, groupby, ncol
using DataFrames: nrow, AbstractDataFrame, groupby

"""
potential_equivalents(cell::AbstractMatrix; tolerance::Real=$(default_tolerance))
Expand Down Expand Up @@ -94,10 +94,10 @@ function inner_translations_impl(fractional::AbstractMatrix,
tolerance::Real=default_tolerance)
@assert is_unitful(fractional) == Val{:unitless}()
if length(species) size(fractional, 2)
Log.error("Size of species and fractional positions do not match")
error("Size of species and fractional positions do not match")
end
if size(cell, 2) size(fractional, 1)
Log.error("Size of cell and fractional positions do not match")
error("Size of cell and fractional positions do not match")
end
grubcell = gruber(cell)

Expand Down Expand Up @@ -232,9 +232,9 @@ function primitive_impl(cell::AbstractMatrix,
species::AbstractVector;
tolerance::Real=default_tolerance)
if size(cartesian, 2) length(species)
Log.error("Positions and species have incompatible sizes")
error("Positions and species have incompatible sizes")
end
size(cell, 2) == size(cartesian, 1) || Log.error("Cell and positions are incompatible")
size(cell, 2) == size(cartesian, 1) || error("Cell and positions are incompatible")
size(cartesian, 2) == 0 && return cell, Int64[1:length(species)...]

grubcell = gruber(cell)
Expand All @@ -259,7 +259,7 @@ function primitive_impl(cell::AbstractMatrix,
reverse!(index)
trial = trans[:, index]
end
det(ustrip(trial)) < 0e0 && Log.error("Negative volume")
det(ustrip(trial)) < 0e0 && error("Negative volume")

int_cell = inv(trial) * cell
all(abs.(int_cell - round.(Integer, int_cell) .< 1e-8)) || continue
Expand All @@ -270,12 +270,12 @@ function primitive_impl(cell::AbstractMatrix,

# Found the new cell with smallest volume (e.g. primivite)
if V volume(grubcell) - tolerance * unit(V)
Log.error("Found translation but no primitive cell.")
error("Found translation but no primitive cell")
end

# now creates new lattice.
indices = Int64[]
Log.debug("Found gruber cell $(grubcell)")
@debug "Found gruber cell $(grubcell)"

for site in 1:size(cartesian, 2)
position = into_cell(cartesian[:, site], new_cell; tolerance=tolerance)
Expand All @@ -288,14 +288,14 @@ function primitive_impl(cell::AbstractMatrix,
end
end

length(species) % length(indices) 0 && Log.error(
length(species) % length(indices) 0 && error(
"Nb of atoms in output not multiple of input: " *
"$(length(species)) % $(length(indices)) ≠ 0"
)

abs(
length(species) * volume(new_cell) - length(indices) * volume(cell)
) < tolerance * unit(volume(new_cell))|| Log.error(
) < tolerance * unit(volume(new_cell))|| error(
"Size and volumes do not match: " *
"abs($(length(species)) * $(volume(new_cell)) - $(length(indices)) *" *
"$(volume(cell))) ≥ $(tolerance * unit(volume(new_cell)))"
Expand Down Expand Up @@ -340,12 +340,11 @@ function space_group_impl(cell::AbstractMatrix,
end
end
end
Log.info(
"$(length(result)) symmetry operations found, with " *
"$(count(result) do op
all(abs.(ustrip(op(zeros(eltype(cartesian), size(translations, 1))))) .< 1e-8)
end) " * "pure symmetries."
)
pure_symms = count(result) do op
all(abs.(ustrip(op(zeros(eltype(cartesian), size(translations, 1))))) .< 1e-8)
end

@info "Symmetry operations" total=length(result) pure=pure_symms
[u for u in result]
end

Expand All @@ -368,7 +367,7 @@ function space_group(crystal::Crystal, cols::Union{Symbol, AbstractVector{Symbol
end
function space_group(crystal::Crystal, species::AbstractVector{Int64}; kwargs...)
if length(species) nrow(crystal)
Log.error("The number of species and the number of atomic sites do not match")
error("The number of species and the number of atomic sites do not match")
end
space_group(crystal.cell, crystal[:position], species; kwargs...)
end
Expand Down
Loading

0 comments on commit a39da98

Please sign in to comment.