Skip to content

Commit

Permalink
adding info about the functions 1
Browse files Browse the repository at this point in the history
  • Loading branch information
cgtbatista committed Jul 16, 2024
1 parent 07842a9 commit 119ee92
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 181 deletions.
1 change: 0 additions & 1 deletion src/CelluloseBuilder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ include("./cleaning.jl")
include("./crystallographic.jl")
include("./formatter.jl")
include("./nfragments.jl")
include("./pbc.jl")
include("./systemgenerator.jl")

end
4 changes: 1 addition & 3 deletions src/cellulose.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ function cellulosebuilder(a::Int64, b::Int64, c::Int64; phase="Iβ", pbc=nothing
push!(tmpfragments, new_pdbname)
end
println(" + using the CHARMM topology file to build the final PDB/PSF with the fragments")
#topology_file = "/home/geckodo/Documents/dupree/fibril/cellulose-builder/top_all36_carb.rtf"
#topology_file = "/home/user/Documents/phd/dupree/fibril/cellulose-builder/top_all36_carb.rtf"
#topology_file = "./src/toppar/top_all36_carb.rtf"

vmdoutput2 = _exporting_PDBfile(phase, 2*xyzsize[3], tmpfragments, topology_file, covalent=covalent, vmd=vmd)

destination_path = pwd()
Expand Down
16 changes: 16 additions & 0 deletions src/cleaning.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
"""
cleaning_tmpfiles()
Cleaning all the *.pdb, *.tcl, and *xyz temporary files inside the /tmp folder.
### Examples
```julia-repl
julia > cleaning_tmpfiles()
```
"""

function cleaning_tmpfiles()
files = readdir("/tmp")
for file in files
Expand Down
199 changes: 173 additions & 26 deletions src/crystallographic.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"""
gettingBasisVectors(lattice_vector::Vector{Int64}, uc_parameters::Vector{Vector{Float64}})
gettingBasisVectors(lattice_vector::Vector{Int64}, phase::String)
This function aims to return the basis vectors for the unit cell given the unit cell lattice and paramenters. The return is a `Vector{Vector{Float64}}` structured as
This function aims to return the basis vectors for the unit cell given an unit cell lattice and its paramenters. The return is a `Vector{Vector{Float64}}` structured as
`[xbasisvector, ybasisvector, zbasisvector]`.
## Arguments
- `lattice_vector::Vector{Int64}`: The lattice vector of the unit cell.
- `uc_parameters::Vector{Vector{Float64}}`: The unit cell parameters. It can be rightly obtained from the `get_crystallographic_info()` function.
- `phase`: The cellulose polymorph crystal to base the crystallographic information.
### Examples
Expand All @@ -20,11 +22,6 @@ julia >
"""

function gettingBasisVectors(lattice_vector::Vector{Int64}, phase::String)
uc_parameters = get_crystallographic_info(phase)[3]
return gettingBasisVectors(lattice_vector, uc_parameters)
end

function gettingBasisVectors(lattice_vector::Vector{Int64}, uc_parameters::Vector{Vector{Float64}})
a = uc_parameters[1][1]; b = uc_parameters[1][2]; c = uc_parameters[1][3]; ## the coefficients of the unit cell parameters
alpha = uc_parameters[2][1]; beta = uc_parameters[2][2]; gamma = uc_parameters[2][3]; ## the unit cell angles
Expand All @@ -46,6 +43,160 @@ function gettingBasisVectors(lattice_vector::Vector{Int64}, uc_parameters::Vecto
return [ xbasisvector, ybasisvector, zbasisvector ]
end

function gettingBasisVectors(lattice_vector::Vector{Int64}, phase::String)
uc_parameters = get_crystallographic_info(phase)[3]
return gettingBasisVectors(lattice_vector, uc_parameters)
end


"""
gettingPBC(xsize::Int64, ysize::Int64, zsize::Int64, phase::String; pbc=nothing)
gettingPBC(xyzsizes::Vector{Int64}, phase::String; pbc=nothing)
This function aims to return the crystallographic information for the setted cellulose phase. The information is related to the CHARMM atomnames, the unit cell
parameters and the fractional coordinates of the asymetric unit.
## Arguments
- `xyzsizes::Vector{Int64}`: The number of unit cells along x, y and z axes (`a`, `b` and `c`).
- `xsize::Int64`: The number of unit cells along x axis (`a`).
- `ysize::Int64`: The number of unit cells units along y axis (`b`).
- `zsize::Int64`: The number of unit cells units along z axis (`c`).
- `phase::String`: The cellulose phase. It could be `Iβ`, `Iα`, `II` or `III`.
- `pbc=nothing`: The periodic boundary conditions to be applied. It's could be around `:A`, `:B`, or both directions `:ALL`. The default is `nothing`.
### Examples
```julia-repl
julia >
```
"""

function gettingPBC(xyzsizes::Vector{Int64}, phase::String; pbc=nothing)
xsize = xyzsizes[1]; ysize = xyzsizes[2]; zsize = xyzsizes[3];
return gettingPBC(xsize, ysize, zsize, phase; pbc=pbc)
end

function gettingPBC(xsize::Int64, ysize::Int64, zsize::Int64, phase::String; pbc=nothing)
if phase == "I-BETA" || phase == "Ib" || phase == ""
if pbc == :all || pbc == :All || pbc == :ALL
xsize += 1; ysize += 1;
println(" periodic boundary conditions will be applied in a and b crystalographic directions.")
println(" surfaces (1 0 0), (2 0 0), (0 1 0), and (0 2 0) will be exposed!")
elseif pbc == :a || pbc == :A
xsize += 1;
println(" periodic boundary conditions will be applied in a crystalographic direction.")
println(" surfaces (1 0 0), (2 0 0), and (0 1 0) will be exposed!")
elseif pbc == :b || pbc == :B
ysize += 1;
println(" periodic boundary conditions will be applied in b crystalographic direction.")
println(" surfaces (1 0 0), (0 1 0), and (0 2 0) will be exposed!")
elseif isnothing(pbc)
println(" periodic boundary conditions will not be special applied.")
println(" default translational symmetry will be applied with the surfaces (1 0 0) and (0 1 0) exposed!")
end
elseif phase == "I-ALPHA" || phase == "Ia" || phase == ""
if !isnothing(pbc)
println(" periodic boundary conditions $pbc will not be applied in the Iα phase, because it is not valid!")
println(" default translational symmetry will be applied with the surfaces (1 0 0) and (0 1 0) exposed!")
else
println(" periodic boundary conditions will not be special applied.")
println(" default translational symmetry will be applied with the surfaces (1 0 0) and (0 1 0) exposed!")
end
elseif phase == "II"
if pbc == :all || pbc == :All || pbc == :ALL
xsize += 1;
println(" periodic boundary conditions will be applied in a and b crystalographic directions.")
println(" surfaces (1 0 0), (2 0 0), (0 1 0), and (0 2 0) will be exposed!")
elseif pbc == :a || pbc == :A
xsize += 1;
println(" periodic boundary conditions will be applied in a crystalographic direction.")
println(" surfaces (1 0 0), (2 0 0), and (0 1 0) will be exposed!")
elseif pbc == :b || pbc == :B
ysize += 1;
println(" periodic boundary conditions will be applied in b crystalographic direction.")
println(" surfaces (1 0 0), (0 1 0), and (0 2 0) will be exposed!")
elseif isnothing(pbc)
println(" periodic boundary conditions will not be special applied.")
println(" default translational symmetry will be applied with the surfaces (1 0 0) and (0 1 0) exposed!")
end
elseif phase == "III"
if !isnothing(pbc)
println(" periodic boundary conditions $pbc will not be applied in the Iα phase, because it is not valid!")
println(" default translational symmetry will be applied with the surfaces (1 0 0) and (0 1 0) exposed!")
else
println(" periodic boundary conditions will not be special applied.")
println(" default translational symmetry will be applied with the surfaces (1 0 0) and (0 1 0) exposed!")
end
end
return [xsize, ysize, zsize]
end

function PBCtools(phase, pbc, nfrag, xsize, ysize, xyzfile, vmd)

forbbiden=Int64[]; remainder=Int64[];

if phase == "I-BETA" || phase == "Ib" || phase == ""

a=nfrag; boundary=1; n_forbbiden=0; upper=nfrag-1;

if pbc == :all || pbc == :ALL || pbc == :All
for b in collect(boundary:1:ysize)
n_forbbiden = (2*xsize-1)*b - 1
push!(forbbiden, convert(Int64, n_forbbiden))
end
for b in collect(boundary:1:xsize)
a = a - 1
push!(forbbiden, convert(Int64, a))
end
elseif pbc == :a || pbc == :A
for b in collect(boundary:1:ysize)
n_forbbiden = (2*xsize-1)*b - 1
push!(forbbiden, convert(Int64, n_forbbiden))
end
elseif pbc == :b || pbc == :B
for b in collect(boundary:1:xsize)
a = a - 1
push!(forbbiden, convert(Int64, a))
end
end

for num in 0:upper
dummy_logical = 1
for ith_forbs in forbbiden
if num == ith_forbs
dummy_logical = 0
break
end
end
if dummy_logical == 1
remainder = push!(remainder, convert(Int64, num))
end
end

sel_fragments = join(remainder, " "); n_fragments = length(remainder);

new_xyzfile = "/tmp/cellulose" * ".xyz"
vmdinput_file = tempname() * ".tcl"

vmdinput = open(vmdinput_file, "w")
Base.write(vmdinput, "mol new \"$xyzfile\" \n")
Base.write(vmdinput, "set sel [ atomselect top \"fragment $sel_fragments\" ] \n")
Base.write(vmdinput, "\$sel writexyz \"$new_xyzfile\" \n")
Base.write(vmdinput, "exit \n")
Base.close(vmdinput)
vmdoutput = split(Base.read(`$vmd -dispdev text -e $vmdinput_file`, String), "\n")

end

return new_xyzfile, sel_fragments, n_fragments

end


"""
Expand Down Expand Up @@ -75,19 +226,6 @@ julia >
"""

function transform_AsymUnits(phase::String)
raw_AsymUnit = get_crystallographic_info(phase)[2]
return transform_AsymUnits(raw_AsymUnit, phase)
end

function transform_AsymUnits(x::Vector{Float64}, y::Vector{Float64}, z::Vector{Float64}, phase::String)
if length(x) != length(y) || length(y) != length(z)
error("The number of x, y, and z coordinates must be the same.")
end
raw_AsymUnit = [ [ i, j, k ] for (i, j, k) in zip(x, y, z) ]
return transform_AsymUnits(raw_AsymUnit, phase)
end

function transform_AsymUnits(raw_AsymUnit::Vector{Vector{Float64}}, phase::String)
xtemp = Float64[]; ytemp = Float64[]; ztemp = Float64[];
if phase == "I-BETA" || phase == "Ib" || phase == "" || phase == "II" || phase == "III"
Expand All @@ -113,8 +251,18 @@ function transform_AsymUnits(raw_AsymUnit::Vector{Vector{Float64}}, phase::Strin
return [ [ i, j, k ] for (i, j, k) in zip(xtemp, ytemp, ztemp) ]
end

function transform_AsymUnits(phase::String)
raw_AsymUnit = get_crystallographic_info(phase)[2]
return transform_AsymUnits(raw_AsymUnit, phase)
end


function transform_AsymUnits(x::Vector{Float64}, y::Vector{Float64}, z::Vector{Float64}, phase::String)
if length(x) != length(y) || length(y) != length(z)
error("The number of x, y, and z coordinates must be the same.")
end
raw_AsymUnit = [ [ i, j, k ] for (i, j, k) in zip(x, y, z) ]
return transform_AsymUnits(raw_AsymUnit, phase)
end


"""
Expand All @@ -140,12 +288,6 @@ julia >
"""

function unitcell2cartesian(cell_dim::Vector{Int64}, phase::String)
fractional_coords = transform_AsymUnits(phase)
uc_parameters = get_crystallographic_info(phase)[3]
return unitcell2cartesian(cell_dim, fractional_coords, uc_parameters)
end

function unitcell2cartesian(cell_dim::Vector{Int64}, fractional_coords::Vector{Vector{Float64}}, uc_parameters::Vector{Vector{Float64}})

x = Vector{Float64}[]; y = Vector{Float64}[]; z = Vector{Float64}[]; ## Vector of vectors to store the cartesian coordinates for each unit cell
Expand Down Expand Up @@ -190,6 +332,11 @@ function unitcell2cartesian(cell_dim::Vector{Int64}, fractional_coords::Vector{V
return x, y, z
end

function unitcell2cartesian(cell_dim::Vector{Int64}, phase::String)
fractional_coords = transform_AsymUnits(phase)
uc_parameters = get_crystallographic_info(phase)[3]
return unitcell2cartesian(cell_dim, fractional_coords, uc_parameters)
end



Expand Down
54 changes: 50 additions & 4 deletions src/nfragments.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
"""
picking_fragments(vmdoutput)
Cleaning all the *.pdb, *.tcl, and *xyz temporary files inside the /tmp folder.
Usualy, the VMD output has the type `Vector{SubString{String}}`.
### Examples
```julia-repl
julia > picking_fragments(vmdoutput)
1817-element Vector{SubString{String}}:
"Info) VMD for LINUXAMD64, version 1.9.4a57 (April 27, 2022)"
"Info) http://www.ks.uiuc.edu/Research/vmd/ "
"Info) Email questions and bug reports to vmd@ks.uiuc.edu "
"Info) Please include this reference in published work using VMD: "
"Info) Humphrey, W., Dalke, A. and Schulten, K., `VMD - Visual "
"Info) Molecular Dynamics', J. Molec. Graphics 1996, 14.1, 33-38."
"Info) -------------------------------------------------------------"
"Info) Multithreading available, 24 CPUs."
"Info) CPU features: SSE2 SSE4.1 AVX AVX2 FMA F16 HT "
"Info) Free system memory: 19GB (61%)"
"Info) Creating CUDA device pool and initializing hardware..."
"Info) Detected 1 available CUDA accelerator::"
"Info) [0] NVIDIA GeForce RTX 40" ⋯ 18 bytes ⋯ "5 GHz, 7.7GB RAM SP64 KT AE2 ZC"
"Info) Detected 1 available TachyonL/OptiX ray tracing accelerator"
"Info) Compiling OptiX shaders on 1 target GPU..."
"Info) Dynamically loaded 3 plugins in directory:"
"Info) /usr/local/lib/vmd/plugins/LINUXAMD64/molfile"
"2.0"
"psfgen) reading topology file /" ⋯ 47 bytes ⋯ "Z/src/toppar/top_all36_carb.rtf"
""
"psfgen) \$Id: top_allxx_sugar.inp,v 1.106 2014/08/19 19:07:43 alex Exp \$"
"psfgen) >>>>>>>>>>>> All-hydrogen topologies used in the <<<<<<<<<<<<<<<<"
"psfgen) >>>>> development of the CHARMM carbohydrate force field<<<<<<<<"
""
"Info) VMD for LINUXAMD64, version 1.9.4a57 (April 27, 2022)"
"Info) Exiting normally."
""
```
"""

function picking_fragments(vmdoutput)
nfrag = nothing
nfragments = nothing
for id in eachindex(vmdoutput)
str = string(vmdoutput[id])
if occursin("Fragments:", str)
nfrag = parse(Int64, split(str)[3])
elseif isnothing(nfrag) && id == length(vmdoutput)
nfragments = parse(Int64, split(str)[3])
elseif isnothing(nfragments) && id == length(vmdoutput)
error("The VMD output file does not contain the number of fragments.")
end
end
return nfrag
return nfragments
end
Loading

0 comments on commit 119ee92

Please sign in to comment.