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

CLI: Add cli to project #20

Merged
merged 13 commits into from
Jul 24, 2024
Merged
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
12 changes: 12 additions & 0 deletions Comonicon.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name = "vibrationalanalysis"

[install]
completion = true
quiet = false
compile = "min"
optimize = 2

[command]
static=true
width=100
dash=false
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ authors = ["Josef M. Gallmetzer"]
version = "0.1.8"

[deps]
Comonicon = "863f3e99-da2a-4334-8734-de3dacbe5542"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@
This package provides tools to perform [vibrational analysis](https://gaussian.com/vib/) of molecules. It is based on the output of QMCFC and [PQ](https://github.com/MolarVerse/PQ) molecular dynamics codes developed at the [University of Innsbruck](https://www.uibk.ac.at/).

## Installation
To install the package, run the following command in the Julia REPL:
```julia-repl
julia> ]
pkg> add VibrationalAnalysis
```
using Pkg
Pkg.add("VibrationalAnalysis")

## Intallation of the CLI
If you want to use the command line interface, you can install it by running the following command:
```julia-repl
julia> using VibrationalAnalysis
julia> VibrationalAnalysis.comonicon_install()
```
Make sure you have `~/.julia/bin` in your PATH.

## Usage
```julia-repl
Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- "src/main.jl"
1 change: 1 addition & 0 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using VibrationalAnalysis; VibrationalAnalysis.comonicon_install()
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ makedocs(
pages = [
"Home" => "index.md",
"Installation" => "installation.md",
"CLI" => "cli.md",
"Examples" => "examples.md",
"License" => "license.md",
"API" => "api.md",
Expand Down
30 changes: 30 additions & 0 deletions docs/src/cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Intallation of the CLI

If you want to use the command line interface, you can install it by running the following command:

```julia-repl
julia> using VibrationalAnalysis
julia> VibrationalAnalysis.comonicon_install()
```
Make sure you have `~/.julia/bin` in your PATH.

or by running the following command:

```bash
julia -e 'using Pkg; Pkg.add("VibrationalAnalysis"); using VibrationalAnalysis; VibrationalAnalysis.comonicon_install()'
```

or by build the package from in your default environment:

```julia-repl
julia> using Pkg
julia> Pkg.build("VibrationalAnalysis")
```

## Usage

Run the following command to see the available options:

```bash
vibrationalanalysis -h
```
4 changes: 4 additions & 0 deletions src/VibrationalAnalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ julia> write_wavenumber_intensity(wavenumbers, intensities, filename="wavenumber
"""
module VibrationalAnalysis

using Printf
using LinearAlgebra
using Comonicon

include("massesdict.jl")
include("read_files.jl")
Expand All @@ -35,5 +37,7 @@ include("transformation.jl")
include("observables.jl")
include("write.jl")
include("calculate.jl")
include("check.jl")
include("main.jl")

end # module VibrationalAnalysis
83 changes: 5 additions & 78 deletions src/calculate.jl
Original file line number Diff line number Diff line change
@@ -1,79 +1,4 @@
export calculate, read_calculate

"""
read_calculate(rst_file, hessian_file; wavenumber=wavenumber_kcal)

Reads the restart file, the hessian and the atom charges and calculates the wavenumbers, force constants and reduced masses.

# Arguments
- `rst_file::String`: The restart file.
- `hessian_file::String`: The hessian file.

# Keyword Arguments
- `wavenumber::Function`: The wavenumber function to use. Either `wavenumber_kcal`, `wavenumber_eV` or `wavenumber_hartree`. Default is `wavenumber_kcal`.

# Returns
- `wavenumbers::Vector{Float64}`: The wavenumbers.
- `force_constants::Vector{Float64}`: The force constants.
- `reduced_masses::Vector{Float64}`: The reduced masses.

# Example
```julia-repl
julia> read_calculate("restart.rst", "hessian.dat")
```
"""
function read_calculate(rst_file::String, hessian_file::String; wavenumber = wavenumber_kcal)

# Read restart restart file
atom_names, atom_masses, atom_coords, atom_types = read_rst(rst_file)

# Read the hessian
hessian = read_hessian(hessian_file)

wavenumbers, force_constants, reduced_masses = calculate(atom_masses, atom_coords, hessian, wavenumber=wavenumber)

return wavenumbers, force_constants, reduced_masses
end

"""
read_calculate(rst_file, hessian_file, moldescriptor_file; wavenumber=wavenumber_kcal)

Reads the restart file, the hessian and the atom charges and calculates the wavenumbers, intensities, force constants and reduced masses.

# Arguments
- `rst_file::String`: The restart file.
- `hessian_file::String`: The hessian file.
- `moldescriptor_file::String`: The moldescriptor file.

# Keyword Arguments
- `wavenumber::Function`: The wavenumber function to use. Either `wavenumber_kcal`, `wavenumber_eV` or `wavenumber_hartree`. Default is `wavenumber_kcal`.

# Returns
- `wavenumbers::Vector{Float64}`: The wavenumbers.
- `intensities::Vector{Float64}`: The intensities.
- `force_constants::Vector{Float64}`: The force constants.
- `reduced_masses::Vector{Float64}`: The reduced masses.

# Example
```julia-repl
julia> read_calculate("restart.rst", "hessian.dat", "moldescriptor.dat")
```
"""
function read_calculate(rst_file::String, hessian_file::String, moldescriptor_file::String; wavenumber = wavenumber_kcal)

# Read restart restart file
atom_names, atom_masses, atom_coords, atom_types = read_rst(rst_file)

# Read the hessian
hessian = read_hessian(hessian_file)

# Read the atom charges
atom_charges = read_moldescriptor(moldescriptor_file, atom_names, atom_types)

wavenumbers, intensities, force_constants, reduced_masses = calculate(atom_masses, atom_coords, atom_charges, hessian, wavenumber=wavenumber)

return wavenumbers, intensities, force_constants, reduced_masses
end
export calculate

"""
calculate(atom_masses, atom_coords, atom_charges, hessian)
Expand All @@ -92,6 +17,7 @@ Calculates the wavenumbers, force constants and reduced masses from the atom mas
- `wavenumbers::Vector{Float64}`: The wavenumbers.
- `force_constants::Vector{Float64}`: The force constants.
- `reduced_masses::Vector{Float64}`: The reduced masses.
- `eigenvectors_internal_normalized::Matrix{Float64}`: The eigenvectors in internal coordinates.

# Example
```julia-repl
Expand All @@ -113,7 +39,7 @@ function calculate(atom_masses::Vector{Float64}, atom_coords::Matrix{Float64}, h
reduced_masses = reduced_mass(normalization)
force_constants = force_constant(omega, reduced_masses)

return wavenumbers, force_constants, reduced_masses
return wavenumbers, force_constants, reduced_masses, eigenvectors_internal_normalized
end

"""
Expand All @@ -135,6 +61,7 @@ Calculates the wavenumbers, intensities, force constants and reduced masses from
- `intensities::Vector{Float64}`: The intensities.
- `force_constants::Vector{Float64}`: The force constants.
- `reduced_masses::Vector{Float64}`: The reduced masses.
- `eigenvectors_internal_normalized::Matrix{Float64}`: The eigenvectors in internal coordinates.

# Example
```julia-repl
Expand All @@ -157,5 +84,5 @@ function calculate(atom_masses::Vector{Float64}, atom_coords::Matrix{Float64}, a
intensities = infrared_intensity(eigenvectors_internal_normalized, atom_charges, reduced_masses)
force_constants = force_constant(omega, reduced_masses)

return wavenumbers, intensities, force_constants, reduced_masses
return wavenumbers, intensities, force_constants, reduced_masses, eigenvectors_internal_normalized
end
27 changes: 27 additions & 0 deletions src/check.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
check_unit(unit::String)

Check if the unit is valid.

# Arguments
- `unit::String`: The unit to check.

# Returns
- `function`: The wavenumber function to use.
"""
function check_unit(unit::String)

# Check if the unit is valid - lowercase
unit = lowercase(unit)

# Check if the unit is valid
if unit == "kcal"
return wavenumber_kcal
elseif unit == "hartree"
return wavenumber_hartree
elseif unit == "ev"
return wavenumber_eV
else
throw(ArgumentError("Invalid unit. Options are kcal, hartree and eV."))
end
end
68 changes: 68 additions & 0 deletions src/main.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import VibrationalAnalysis: check_unit

"""
CLI to calculate VibrationalAnalysis on a QMCFC or a PQ input.

# Info

Calculate the wavenumbers, intensities, force constants, reduced masses and eigenvectors of a QMCFC or a PQ input.

# Args

- `restart`: The restart file.
- `hessian`: The hessian file.

# Options

- `--modesmatrix`: Write the modes in matrix notation to a file. If not specified, the modes in matrix notation will not be written.
- `--moldescriptor`: The moldescriptor file. If not specified, the intensities will not be calculated.
- `-o, --output`: The name of the output file. Default is stdout.
- `-u, --unit`: The energy unit in the Hessian file. Options are kcal, Hartree and eV. Default is kcal.

# Flags

- `--modes`: Write the modes in xyz format. If not specified, the modes will not be written.

"""
@main function vibrationalanalalysis(restart::String, hessian::String; unit = "kcal", moldescriptor = nothing, output = nothing, modes_matrix = nothing, modes::Bool = false)

# Check if the unit is valid
wavenumber = check_unit(unit)

# Read restart restart file
atom_names, atom_masses, atom_coords, atom_types = read_rst(restart)

# Read the hessian
hessian = read_hessian(hessian)

# if moldescriptor_file is not nothing
if moldescriptor == nothing

# calculate the wavenumbers, force constants, reduced masses and eigenvectors
wavenumbers, force_constants, reduced_masses, eigenvectors_internal_normalized = calculate(atom_masses, atom_coords, hessian, wavenumber = wavenumber)

# write wavenumbers, force constants, reduced masses
write_calculate_output(wavenumbers, force_constants, reduced_masses, filename = output)
else

# Read the atom charges
atom_charges = read_moldescriptor(moldescriptor, atom_names, atom_types)

# calculate the wavenumbers, intensities, force constants, reduced masses and eigenvectors
wavenumbers, intensities, force_constants, reduced_masses, eigenvectors_internal_normalized = calculate(atom_masses, atom_coords, atom_charges, hessian, wavenumber = wavenumber)

write_calculate_output(wavenumbers, intensities, force_constants, reduced_masses, filename = output)
end

# write the modes to a file
if modes_matrix != nothing
write_modes(eigenvectors_internal_normalized, filename = modes_matrix)
end

# write modes in xyz format
if modes
write_modes(eigenvectors_internal_normalized, atom_coords, atom_names, filename = "modes")
end

return
end
2 changes: 1 addition & 1 deletion src/observables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ end
"""
force_constant(wavenumbers::Vector{Float64}, reduced_mass::Vector{Float64}) -> force_const::Vector{Float64}

Calculate the force constant from the wavenumbers and the reduced mass.
Calculate the force constant from the wavenumbers and the reduced mass in mdyn Å^-1.

# Arguments
- `wavenumbers::Vector{Float64}`: The wavenumbers.
Expand Down
Loading
Loading