split.pdb {Rpdb} | R Documentation |
Divide and Reassemble ‘pdb’ Objects
Description
split
divides a ‘pdb’ object by groups of atoms defined by
f
. unsplit
reverses the effect of split
.
Usage
## S3 method for class 'pdb'
split(x, f, drop = FALSE, ...)
## S3 method for class 'pdb'
unsplit(value, f, drop = FALSE, ...)
Arguments
x |
an object of class ‘pdb’ to be divided into groups. |
f |
a ‘factor’ in the sense that
|
drop |
logical indicating if levels that do not occur should be
dropped (if |
... |
further potential arguments passed to methods. |
value |
a list of 'pdb' objects compatible with a splitting of
|
Details
split
produce a list of ‘pdb’ objects with the same
cryst1
, title
and remark
components as x
. Only
its atoms
component is splitted while its conect
component is
cleaned to keep only the meaningful connectivity for each ‘pdb’ object
of the list returned by the function. unlist
produce a ‘pdb’
object with the same cryst1
, title
and remark
components
as the first element of value
. The atoms
and conect
components of all the elements of value
are combined by row.
Value
The value returned from split
is a list of ‘pdb’
objects containing the data for the groups of atoms. The components of the
list are named by the levels of f
(after converting to a factor, or if
already a factor and drop=TRUE
, dropping unused levels).
unsplit
returns a ‘pdb’ object for which split(x, f)
equals value
.
See Also
Examples
### Split a pdb file by residue IDs and write them into separate files
x <- read.pdb(system.file("examples/PCBM_ODCB.pdb", package="Rpdb"))
file.names <- paste0(x$atoms$resname, "_", x$atoms$resid, ".pdb")
file.names <- unique(file.names)
pdb.resid <- split(x, x$atoms$resid)
length(pdb.resid)
useless <- mapply(write.pdb, pdb.resid, file.names)
# Cleanup
unlink(file.names)