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

Update python part to AtomsBase 0.4 #38

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ on:
types:
- created
workflow_dispatch:
inputs:
lookback:
default: 3
permissions:
actions: read
checks: read
contents: write
deployments: read
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
Expand Down
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AtomsIO"
uuid = "1692102d-eeb4-4df9-807b-c9517f998d44"
authors = ["Michael F. Herbst <[email protected]> and contributors"]
version = "0.2.3"
version = "0.2.5"

[deps]
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"
Expand All @@ -15,10 +15,10 @@ UnitfulAtomic = "a7773ee8-282e-5fa2-be4e-bd808c38a91a"
XCrySDenStructureFormat = "02310045-4665-40c9-a658-98c497d2eca9"

[compat]
AtomsBase = "0.3"
AtomsBaseTesting = "0.1"
AtomsBase = "0.4"
AtomsBaseTesting = "0.2"
Chemfiles = "0.10.41"
ExtXYZ = "0.1.14"
ExtXYZ = "0.2"
PeriodicTable = "1"
Reexport = "1"
Unitful = "1"
Expand Down
6 changes: 3 additions & 3 deletions lib/AtomsIOPython/Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name = "AtomsIOPython"
uuid = "9e4c859b-2281-48ef-8059-f50fe53c37b0"
authors = ["Michael F. Herbst <[email protected]> and contributors"]
version = "0.1.2"
version = "0.1.3"

[deps]
ASEconvert = "3da9722f-58c2-4165-81be-b4d7253e8fd2"
AtomsIO = "1692102d-eeb4-4df9-807b-c9517f998d44"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[compat]
ASEconvert = "0.1.4"
AtomsBaseTesting = "0.1"
ASEconvert = "0.1.8"
AtomsBaseTesting = "0.2"
AtomsIO = "0.2"
Reexport = "1"
julia = "1.6"
Expand Down
14 changes: 6 additions & 8 deletions lib/AtomsIOPython/src/AtomsIOPython.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ module AtomsIOPython
using Reexport
@reexport using AtomsIO

include("ase.jl")

export AseParser
include("ase.jl")

function __init__()
# Append python-based parsers to the parser list in AtomsIO.
function AtomsIO.atomsio_extra_parsers(::AtomsIO.PythonParsers)
# Register the python-based parsers with AtomsIO
#
# Note: For reproducibility reasons changing the order of these parsers is a
# *breaking change* (as it alters the behaviour of AtomsIO.load_system).
# Moreover since not all users will want to rely on Python dependencies, it is
# crucial that the python-based parsers are *appended* to this list.
parsers = AbstractParser[AseParser(), ]
append!(AtomsIO.DEFAULT_PARSER_ORDER, parsers)
AbstractParser[AseParser(), ]
end

end
2 changes: 1 addition & 1 deletion lib/AtomsIOPython/test/ase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function make_ase_system(args...; drop_atprop=Symbol[], kwargs...)
end

@testset "ASE parser has been added" begin
@test AseParser() in AtomsIO.DEFAULT_PARSER_ORDER
@test AseParser() in AtomsIO.default_parsers()
end

@testset "ASE system write/read" begin
Expand Down
2 changes: 1 addition & 1 deletion lib/AtomsIOPython/test/comparison.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using AtomsBaseTesting
end

@testset "Test structures from simple XYZ files parse the same" begin
drop_atprop = [:covalent_radius, :vdw_radius, :velocity, :charge, :atomic_mass]
drop_atprop = [:covalent_radius, :vdw_radius, :velocity, :charge, :mass]
drop_sysprop = [:extra_data]
data = make_test_system(; drop_atprop, drop_sysprop, cellmatrix=:lower_triangular)
system = periodic_system(data.atoms, data.box; data.sysprop...)
Expand Down
2 changes: 1 addition & 1 deletion src/extxyz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ExtXYZ
"""
Parse or write file using [ExtXYZ](https://github.com/libAtoms/ExtXYZ.jl)

Supported formats:
Supported formats:
- [XYZ](https://openbabel.org/wiki/XYZ) and [extxyz](https://github.com/libAtoms/extxyz#extended-xyz-specification-and-parsing-tools) files
"""
struct ExtxyzParser <: AbstractParser end
Expand Down
36 changes: 25 additions & 11 deletions src/saveload.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
# The list of parsers in the order to try them.
# Python-based parsers are appended once AtomsIOPython is loaded.
# Note: For reproducibility reasons changing the order of these parsers is a
# *breaking change* (as it alters the behaviour of AtomsIO.load_system).
# Moreover since not all users will want to rely on Python dependencies, it is
# crucial that the python packages are only *appended* to this list.
const DEFAULT_PARSER_ORDER = AbstractParser[
ExtxyzParser(), XcrysdenstructureformatParser(), ChemfilesParser(),
]

# Mechanics to add additional parsers automatically in a well-defined order
# Add marker structs here for every new "category" of parsers that become
# dynamically available (e.g. the PythonParsers() defined in AtomsIOPython)
struct PythonParsers end
atomsio_extra_parsers(marker) = AbstractParser[]

function default_parsers()
# The list of parsers in the order to try them.
# Python-based parsers are appended once AtomsIOPython is loaded,
# since this defines an appropriate method for the PythonParsers() marker struct.
#
# Note: For reproducibility reasons changing the order of these parsers is a
# *breaking change* (as it alters the behaviour of AtomsIO.load_system).
# Moreover since not all users will want to rely on Python dependencies, it is
# crucial that the python packages are only *appended* to this list.

AbstractParser[
ExtxyzParser(), XcrysdenstructureformatParser(), ChemfilesParser(),
atomsio_extra_parsers(PythonParsers())... # Add python parsers if they are available
]
end

function determine_parser(file; save=false, trajectory=false)
idx_parser = findfirst(DEFAULT_PARSER_ORDER) do parser
parsers = default_parsers()
idx_parser = findfirst(parsers) do parser
supports_parsing(parser, file; save, trajectory)
end
if isnothing(idx_parser)
Expand All @@ -22,7 +36,7 @@ function determine_parser(file; save=false, trajectory=false)
end
error(errormsg)
end
DEFAULT_PARSER_ORDER[idx_parser]
parsers[idx_parser]
end


Expand Down
11 changes: 6 additions & 5 deletions test/chemfiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ function make_chemfiles_system(D=3; drop_atprop=Symbol[], infinite=false, kwargs
extra_sysprop=(; extra_data=42.0), cellmatrix=:upper_triangular,
kwargs...)
if infinite
system = isolated_system(data.atoms; data.sysprop...)
cell = IsolatedCell(3)
else
system = periodic_system(data.atoms, data.box; data.sysprop...)
cell = PeriodicCell(; cell_vectors=data.box, periodicity=(true, true, true))
end
system = AtomsBase.FlexibleSystem(data.atoms, cell; data.sysprop...)
merge(data, (; system))
end

@testset "Chemfiles system write / read" begin
system = make_chemfiles_system(; drop_atprop=[:atomic_mass]).system
system = make_chemfiles_system(; drop_atprop=[:mass]).system
mktempdir() do d
outfile = joinpath(d, "output.cml")
save_system(ChemfilesParser(), outfile, system)
Expand All @@ -30,7 +31,7 @@ end

@testset "Chemfiles trajectory write/read" begin
ignore_atprop = [:covalent_radius, :vdw_radius]
systems = [make_chemfiles_system(; drop_atprop=[:atomic_mass]).system for _ in 1:3]
systems = [make_chemfiles_system(; drop_atprop=[:mass]).system for _ in 1:3]
mktempdir() do d
outfile = joinpath(d, "output.cml")
save_trajectory(ChemfilesParser(), outfile, systems)
Expand All @@ -41,7 +42,7 @@ end

test_approx_eq(systems[end], load_system(ChemfilesParser(), outfile);
rtol=1e-6, ignore_atprop)
test_approx_eq(systems[2], load_system(ChemfilesParser(), outfile, 2);
test_approx_eq(systems[2], load_system(ChemfilesParser(), outfile, 2);
rtol=1e-6, ignore_atprop)
end
end
Expand Down
3 changes: 1 addition & 2 deletions test/xsf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ using UnitfulAtomic
function make_xsf_system(D=3; drop_atprop=Symbol[], drop_sysprop=Symbol[], kwargs...)
@assert D == 3 # Only 3D systems are supported
n_atoms = 5 # Copied from AtomsBaseTesting.make_test_system, used for making forces
xsf_drop_atprop = [:velocity, :charge, :atomic_mass, :vdw_radius, :covalent_radius,
:magnetic_moment]
xsf_drop_atprop = [:velocity, :charge, :mass, :vdw_radius, :covalent_radius, :magnetic_moment]
xsf_drop_sysprop = [:extra_data, :charge, :multiplicity]
force = [randn(3)u"Eh_au/Å" for _ in 1:n_atoms]
make_test_system(D; drop_atprop=append!(drop_atprop, xsf_drop_atprop),
Expand Down
Loading