diff --git a/DESCRIPTION b/DESCRIPTION index 14786cd..6addf3c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: raymolecule Type: Package Title: Parse and Render Molecular Structures in 3D -Version: 0.5.1 -Date: 2022-12-09 +Version: 0.5.2 +Date: 2024-2-18 Authors@R: c(person("Tyler", "Morgan-Wall", email = "tylermw@gmail.com", role = c("aut", "cph", "cre"), comment = c(ORCID = "0000-0002-3131-3814"))) Maintainer: Tyler Morgan-Wall @@ -10,11 +10,13 @@ Description: Downloads and parses 'SDF' (Structural Description Format) and 'PDB License: GPL-3 Encoding: UTF-8 Imports: - rayrender, + rayrender (>= 0.31.2), magrittr, PeriodicTable, httr, - rayvertex + rayvertex (>= 0.10.4) LazyData: true -RoxygenNote: 7.1.2 -URL: http://www.raymolecule.com/ +RoxygenNote: 7.3.0 +URL: http://www.raymolecule.com/, + https://github.com/tylermorganwall/raymolecule +BugReports: https://github.com/tylermorganwall/raymolecule/issues diff --git a/R/convert_color.R b/R/convert_color.R index dfe6e3c..ea03794 100644 --- a/R/convert_color.R +++ b/R/convert_color.R @@ -10,7 +10,7 @@ #' #none convert_color = function(color, as_hex = FALSE) { if(inherits(color,"character")) { - color = as.vector(col2rgb(color))/255 + color = as.vector(grDevices::col2rgb(color))/255 } stopifnot(all(color <= 1)) stopifnot(all(color >= 0)) diff --git a/R/generate_atom_scene.R b/R/generate_atom_scene.R index bc064c5..5842343 100644 --- a/R/generate_atom_scene.R +++ b/R/generate_atom_scene.R @@ -47,6 +47,7 @@ generate_atom_scene = function(model, x=0, y=0, z=0, scale = 1, center = TRUE, material = rayrender::glossy, material_vertex = material_list(type="phong")) { mat_info = material() + mat_info = mat_info[[1]] if(!mat_info$type %in% c("glossy","diffuse", "dielectric")) { stop("material() must be either `glossy`, `diffuse`, or `dielectric`") } @@ -78,7 +79,7 @@ generate_atom_scene = function(model, x=0, y=0, z=0, scale = 1, center = TRUE, material=material(color=atomcol)) counter = counter + 1 } - return(do.call(rbind, scenelist)) + return(do.call("rbind", scenelist)) } else { scene = list() for (i in 1:nrow(atoms)) { @@ -89,8 +90,8 @@ generate_atom_scene = function(model, x=0, y=0, z=0, scale = 1, center = TRUE, atomcol = "grey5" } material_atom = material_vertex - material_atom$diffuse = atomcol - material_atom$ambient = atomcol + material_atom$diffuse = as.numeric(grDevices::col2rgb(atomcol))/255 + material_atom$ambient = as.numeric(grDevices::col2rgb(atomcol))/255 material_atom$ambient_intensity = 0.3 atomsize = (PeriodicTable::mass(atoms$type[i])/14)^(1/3) scene = add_shape(scene, sphere_mesh(position = c(atoms$x[i],atoms$y[i], atoms$z[i]), diff --git a/R/generate_bond_scene.R b/R/generate_bond_scene.R index c334213..def023a 100644 --- a/R/generate_bond_scene.R +++ b/R/generate_bond_scene.R @@ -47,6 +47,7 @@ generate_bond_scene = function(model, x=0, y=0, z=0, scale = 1, center = TRUE, type = "phong", ambient_intensity=0.3)) { mat_info = material() + mat_info = mat_info[[1]] if(!mat_info$type %in% c("glossy","diffuse", "dielectric")) { stop("material() must be either `glossy`, `diffuse`, or `dielectric`") } diff --git a/R/generate_full_scene.R b/R/generate_full_scene.R index ac69b99..5770e17 100644 --- a/R/generate_full_scene.R +++ b/R/generate_full_scene.R @@ -62,6 +62,7 @@ generate_full_scene = function(model, x=0,y=0,z=0, scale = 1, center = TRUE, pat force_single_bonds = FALSE, material = rayrender::glossy, material_vertex = material_list(type="phong")) { mat_info = material() + mat_info = mat_info[[1]] if(!mat_info$type %in% c("glossy","diffuse", "dielectric")) { stop("material() must be either `glossy`, `diffuse`, or `dielectric`") } diff --git a/R/render_model.R b/R/render_model.R index 713be2c..e2e16d1 100644 --- a/R/render_model.R +++ b/R/render_model.R @@ -77,12 +77,14 @@ render_model = function(scene, fov = NULL, angle = c(0,0,0), order_rotation = c( } pathtraced = suppressWarnings(is.null(scene$vertices)) if(pathtraced) { - scene_model = scene[is.na(scene$lightintensity) & + is_not_light = unlist(lapply(scene$material, \(x) x$type)) != "light" + + scene_model = scene[is_not_light & (scene$shape == "cylinder" | scene$shape == "sphere"),] bbox_x = range(scene_model$x,na.rm=TRUE) bbox_y = range(scene_model$y,na.rm=TRUE) bbox_z = range(scene_model$z,na.rm=TRUE) - spheresizes = scene[(scene$shape == "sphere" & scene$type != "light"),4] + spheresizes = unlist(lapply(scene$shape_info, \(x) x[[1]]$radius))[is_not_light] if(length(spheresizes) > 0) { max_sphere_radii = max(spheresizes,na.rm=TRUE) } else { diff --git a/R/util.R b/R/util.R index ddd827f..531b9cb 100644 --- a/R/util.R +++ b/R/util.R @@ -19,7 +19,6 @@ unit_vector = function(v) { #'@title Create Orthonormal Basis from w (z) #' -#'@param v Numeric vector. #'@keywords internal onb_from_w = function(n) { a1 = unit_vector(n) diff --git a/man/convert_color.Rd b/man/convert_color.Rd new file mode 100644 index 0000000..318aeba --- /dev/null +++ b/man/convert_color.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/convert_color.R +\name{convert_color} +\alias{convert_color} +\title{Convert Color} +\usage{ +convert_color(color, as_hex = FALSE) +} +\arguments{ +\item{color}{The color to convert. Can be either a hexadecimal code, or a numeric rgb +vector listing three intensities between `0` and `1`.} +} +\value{ +Color vector +} +\description{ +Convert Color +} +\examples{ +#none +} +\keyword{internal} diff --git a/man/generate_bond_scene.Rd b/man/generate_bond_scene.Rd index b90560a..1f4a2a7 100644 --- a/man/generate_bond_scene.Rd +++ b/man/generate_bond_scene.Rd @@ -14,8 +14,8 @@ generate_bond_scene( force_single_bonds = FALSE, pathtrace = TRUE, material = rayrender::glossy, - material_vertex = material_list(diffuse = "grey33", ambient = "grey33", type = - "phong", ambient_intensity = 0.3) + material_vertex = material_list(diffuse = "grey33", ambient = "grey33", type = "phong", + ambient_intensity = 0.3) ) } \arguments{ diff --git a/man/onb_from_w.Rd b/man/onb_from_w.Rd index b7acb05..a3f91b2 100644 --- a/man/onb_from_w.Rd +++ b/man/onb_from_w.Rd @@ -6,9 +6,6 @@ \usage{ onb_from_w(n) } -\arguments{ -\item{v}{Numeric vector.} -} \description{ Create Orthonormal Basis from w (z) }