Skip to content

Commit

Permalink
adding the other polymorphs, /tmp modification and adding text files
Browse files Browse the repository at this point in the history
  • Loading branch information
cgtbatista committed Jul 17, 2024
1 parent 119ee92 commit b1c2c9e
Show file tree
Hide file tree
Showing 13 changed files with 547 additions and 280 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,30 @@
[![Build Status](https://github.com/cgtbatista/CelluloseBuilder.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/cgtbatista/CelluloseBuilder.jl/actions/workflows/CI.yml?query=branch%3Amain)
[![Coverage](https://codecov.io/gh/cgtbatista/CelluloseBuilder.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/cgtbatista/CelluloseBuilder.jl)
[![Coverage](https://coveralls.io/repos/github/cgtbatista/CelluloseBuilder.jl/badge.svg?branch=main)](https://coveralls.io/github/cgtbatista/CelluloseBuilder.jl?branch=main)

A Julia package that reimplements the Cellulose Builder software, aiming to simplify the code and provide more flexibility for dealing with different crystallographic parameters or even newest microfibril models. The package generates cartesian coordinates for a given crystalographic data of the specified structure in XYZ and PDB formats, suitable for using as starting configurations in molecular dynamics simulations and other calculations. The crystaline polymorphs Iα, Iβ, II, and III(I) of practically any size can be constructed, including parallelepipeds, plant cell wall cellulose elementary fibrils of any length, and monolayers. Periodic boundary conditions (PBC) along the crystallographic directions are easily imposed and it can consider covalent bounding through the PBC. The package also generates atom connectivity files in PSF format, required by well-known simulation packages such as NAMD, CHARMM, and others. CelluloseBuilder.jl is written in Julia and should run on any platform that supports Julia and both are freely available.


## Original Script Update

The original [Cellulose Builder script](https://code.google.com/archive/p/cellulose-builder/) is written in bash, Perl, and Tcl, requiring additional software like Octave to run on a personal computer (Gomes and Skaf, 2012). There is an [online version](http://cces-sw.iqm.unicamp.br/cces/admin/cellulose/view;jsessionid=) that is easy to use, however it does not allow adaptations on the source script. Indeed, this julia package still requires the VMD software (psfgen) to work (Humphrey, 1996). Beyond the PSF, other topology formats will be implemented later using TopoTools.

This package, CelluloseBuilder.jl, aims to:

* Simplify the code
* Provide more flexibility for dealing with different parameters
* Implement new features not available in the original version

## Documentation

For more information, please check out our [stable documentation](https://cgtbatista.github.io/CelluloseBuilder.jl/stable/) or [dev documentation](https://cgtbatista.github.io/CelluloseBuilder.jl/dev/).

## Build Status and Coverage

Check out our [build status](https://github.com/cgtbatista/CelluloseBuilder.jl/actions/workflows/CI.yml?query=branch%3Amain) and [code coverage](https://codecov.io/gh/cgtbatista/CelluloseBuilder.jl) reports.

## References

T. C. F. Gomes, M. S. Skaf, J. Comput. Chem. 2012, 33, 1338-1346. [10.1002/jcc.22959](https://onlinelibrary.wiley.com/doi/10.1002/jcc.22959).

W. Humphrey, A. Dalke, K. Schulten, J. Mol. Graph. 1996, 14, 33-38. [10.1016/0263-7855(96)00018-5](https://linkinghub.elsevier.com/retrieve/pii/0263785596000185).
20 changes: 15 additions & 5 deletions src/CelluloseBuilder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@ const DEFAULT_CARB_TOPOLOGY_FILE = "$(@__DIR__)/toppar/top_all36_carb.rtf"
# main cellulose builder function
include("./cellulose.jl")

include("./atomnames.jl")
include("./cleaning.jl")
include("./crystallographic.jl")
## editing the default atomnames
include("./editing_atomnames.jl")

## crystalographic tools to deal with the crystalline cellulose
include("./crystaltoolkit.jl")


include("./formatter.jl")
include("./nfragments.jl")
include("./systemgenerator.jl")
include("./exporting_systems.jl")
include("./PBC.jl")

## picking the number of structure fragments inside a VMD structure loading output
include("./picking_fragments.jl")

## cleaning the temporary files
include("./cleaning_tmpfiles.jl")

end
83 changes: 83 additions & 0 deletions src/PBC.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""
transformingPBC(nfrag::Int64, xsize::Int64, ysize::Int64; phase="Iβ", pbc=nothing, xyzfile="file.xyz", vmd="vmd")
This function applies the periodic boundary conditions on the cellulose fibrils over the axis `a`, `b`, and `both`.
After this transformation, you export the cellulose fibril XYZ file with the cartesian coordinates.
## Arguments
- `nfrag::Int64`: is the number of fragments inside the XYZ file.
- `xsize::Int64`: the number of unit cells along x axis (`a`).
- `ysize::Int64`: the number of unit cells units along y axis (`b`).
### Examples
```jldoctest
julia > transformingPBC(59, 5, 7)
```
"""

function transformingPBC(nfrag::Int64, xsize::Int64, ysize::Int64; phase="", pbc=nothing, xyzfile="file.xyz", vmd="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
29 changes: 0 additions & 29 deletions src/atomnames.jl

This file was deleted.

28 changes: 13 additions & 15 deletions src/cellulose.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Cellulose-builder builds Cartesian coordinates files for cellulose crystalline d
### Examples
```julia-repl
```jldoctest
julia >
Expand Down Expand Up @@ -74,49 +74,47 @@ function cellulosebuilder(a::Int64, b::Int64, c::Int64; phase="Iβ", pbc=nothing
println(" + appling transformations on fractional coordinates needed for the phase $phase.")
println(" + transforming the asymmetric unit to the cartesian coordinates for every [a,b,c] = [$xsize,$ysize,$zsize] Å.")
## PHASES CAN DIFFER...
if phase == "I-BETA" || phase == "Ib" || phase == ""
if phase == "Ib" || phase == "" || phase == "II" || phase == "III" || phase == "III_I" || phase == "III_i" || phase == "IIIi"
xinit, yinit, zinit = unitcell2cartesian(xyzsize[1:2], phase)
end
if phase == "Ia" || phase == ""
xinit, yinit, zinit = unitcell2cartesian(xyzsize, phase)
end
println(" + atomic labels for $phase.")
atomsinit, atomstype = atomsvecString(phase, xyzsize[1], xyzsize[2])
println("")

println(" 2 - Extending the cellulose modifications of the atoms:")
println(" + cleaning the coordinates and atomic labels for $phase.")
atomsclean, xclean, yclean, zclean = XY_coord_trimming(atomsinit, xinit, yinit, zinit, xyzsize, phase)
atomsclean, xclean, yclean, zclean = _XY_trimming_coords(atomsinit, xinit, yinit, zinit, xyzsize, phase=phase)
println(" + expanding the z coordinates for $phase.")
atomsexpnd, xexpnd, yexpnd, zexpnd = Z_propagation(atomsclean, xclean, yclean, zclean, xyzsize[3], phase)
atomsexpnd, xexpnd, yexpnd, zexpnd = _Z_propagation_coords(atomsclean, xclean, yclean, zclean, xyzsize[3], phase=phase)
println(" + picking the number of fragments of the basic structure.")
xyzfile, vmdoutput = _exporting_XYZfile(atomsexpnd, xexpnd, yexpnd, zexpnd)
n_fragments = picking_fragments(vmdoutput)
println("")

println(" 3 - Periodic boundary conditions (PBC) on the $n_fragments fragments: $(pbc)...")
vmdxyz, frag_sel, frag_units = PBCtools(phase, pbc, n_fragments, xyzsize[1], xyzsize[2], xyzfile, vmd)
vmdxyz, frag_sel, frag_units = transformingPBC(n_fragments, xyzsize[1], xyzsize[2], phase=phase, pbc=pbc, xyzfile=xyzfile, vmd=vmd)
println("")

println(" 4 - Generating the PSF/PDB files:")
println(" + writing the PDBs for each of those $frag_units fragment units.")
pdb_basename = _XYZfragments_2_PDB(vmdxyz, frag_sel, vmd=vmd)[1]
pdb_basename = _XYZfragments_2_PDB(vmdxyz, frag_sel, vmd=vmd)[2]
println(" + cleaning each fragment PDB.")
units = Base.split(frag_sel, " ");
tmpfragments = String[];
tmpfragments = String[]; tmpfile = tempname();
for u in units
pdbname = pdb_basename * "_" * u * ".pdb"
new_pdbname = "/tmp/tmp_" * u * ".pdb"
new_pdbname = tmpfile * "_" * u * ".pdb"
_PDBfragment_cleaning(atomstype, pdbname, new_pdbname)
push!(tmpfragments, new_pdbname)
end
println(" + using the CHARMM topology file to build the final PDB/PSF with the fragments")

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

destination_path = pwd()
mv("/tmp/cellulose.xyz", joinpath(destination_path, "cellulose.xyz"), force=true)
mv("/tmp/cellulose.psf", joinpath(destination_path, "cellulose.psf"), force=true)
mv("/tmp/cellulose.pdb", joinpath(destination_path, "cellulose.pdb"), force=true)

cleaning_tmpfiles()
cleaning_tmpfiles("cellulose")
println("")
println(" ... it is done!")

Expand Down
25 changes: 0 additions & 25 deletions src/cleaning.jl

This file was deleted.

40 changes: 40 additions & 0 deletions src/cleaning_tmpfiles.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
cleaning_tmpfiles()
Move the exported files to the work directory and clean all the *.pdb, *.tcl, and *xyz on temporary
files inside the temp folder (it can be different on Linux, Windows and MacOS).
### Arguments
- `filename::String`: main name of the exported file.
- `destination_path`: the default destination folder is the working directory.
### Examples
```jldoctest
julia > cleaning_tmpfiles()
```
"""

function cleaning_tmpfiles(filename::String; destination_path=pwd())

tmp_path = tempdir()

mv(joinpath(tmp_path, "$filename.xyz"), joinpath(destination_path, "$filename.xyz"), force=true)
mv(joinpath(tmp_path, "$filename.psf"), joinpath(destination_path, "$filename.psf"), force=true)
mv(joinpath(tmp_path, "$filename.pdb"), joinpath(destination_path, "$filename.pdb"), force=true)

files = readdir(tmp)
for file in files
if occursin(".pdb", file) || occursin(".xyz", file) || occursin(".tcl", file)
rm(joinpath(tmp_path, file))
end
end

return nothing

end
Loading

0 comments on commit b1c2c9e

Please sign in to comment.