Learn R Programming

Rpdb (version 2.2)

centres: Centres-of-Geometry and Centres-of-Mass

Description

Computes centres-of-geometry and centres-of-mass of groups of atoms.

Usage

centres(...)
"centres"(x, factor = NULL, weights = NULL, unsplit = FALSE, na.rm = FALSE, ...)
"centres"(x, factor = NULL, weights = NULL, unsplit = FALSE, na.rm = FALSE, ...)
"centres"(x, factor = NULL, weights = NULL, unsplit = FALSE, na.rm = FALSE, ...)

Arguments

x
an R object containing atomic coordinates.
factor
a factor used to split the atomic coordinates by groups to compute multiple centres.
weights
a numerical vector containing atomic weights used to compute centres-of-mass.
unsplit
a logical value indicating whether the coordinates of the centres have to be unsplit to repeat their coordinates for each atom used for their calculation (used for wrapping by groups).
na.rm
a logical value indicating whether NA values should be stripped before the computation proceeds.
...
further arguments passed to or from other methods.

Value

‘coords’ containing the coordinates of centres.

Details

centres is a generic function to compute centres-of-geometry and centres-of-mass from an object containing atomic coordinates. For objects of class ‘coords’, ‘atoms’ and ‘pdb’, the coordinates of x are first splitted into groups defined by factor using the split function. For each group, the weighted mean of the x1, x2 and x3 components of x are calculated using weights. By default all atoms are assumed to have the same weight (calculation of centres-of-geometry). Finally, if unplit = TRUE the coordinates of the centres are unsplitted using the unsplit function to assign to each atom the coordinates of the centre to which they are attached (used for wrapping by groups).

For objects of class ‘atoms’ and ‘pdb’ by default factor is set to x$resid and x$coordinates$resid, respectively, to compute the centre-of-geometry of the different resdiues. Notice that coordinates can be neglected for the calculation of the centres using NA values in factor.

See Also

coords, atoms, pdb, elements

and split, unsplit, factor for details about splitting data sets.

Examples

Run this code
# First lets read a pdb file
x <- read.pdb(system.file("examples/PCBM_ODCB.pdb",package="Rpdb"))

# Centres-of-geometry of the residues
centres(x)

# Centre-of-geometry of the whole structure
centres(x, factor = rep(1, natom(x)))
# or
centres(coords(x))

# Centres-of-geometry of the PCB and DCB residues
centres(x, factor = x$atoms$resname)

# Knowing the name of the elements forming
# the C60 of the PCBM molecules (PCB residues)
# we can compute the centres-of-geometry of
# the C60 by neglecting the other atoms of the
# PCB residues.
C60.elename <- paste0("C",sprintf("%0.3d",1:60))

is.PCB <- x$atoms$resname == "PCB" # Produce a mask to select only the PCB residues
is.C60 <- is.PCB & x$atoms$elename %in% C60.elename # Produce a mask to keep only the C60

F <- x$atoms$resid # We use the residue IDs to split the coordinates
F[!is.C60] <- NA # We keep only the atoms of the C60

C60.centres <- centres(x, factor = F)

# Lets check the position of the C60 centres
visualize(x , mode = NULL)
spheres3d(C60.centres)
text3d(Ty(C60.centres, 2), text=paste0("PCB_", rownames(C60.centres)), cex=2)

# Centres-of-mass of the resdiues
symb <- toSymbols(x$atoms$elename) # Convert elename into elemental symbols
# Find the mass of the element in the periodic table
w <- elements[match(symb, elements[,"symb"]),"mass"] 
centres(x, weights =  w)

Run the code above in your browser using DataLab