Learn R Programming

Rpdb (version 2.1)

split.pdb: 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 as.factor(f) defines the grouping, or a list of such factors in which case their interaction is used for the grouping.
drop
logical indicating if levels that do not occur should be dropped (if f is a factor or a list).
value
a list of 'pdb' objects compatible with a splitting of x. Recycling applies if the lengths do not match.
...
further potential arguments passed to methods.

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.

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.

See Also

split, unsplit, pdb

Examples

Run this code
## Split a pdb file by residue IDs and write them into separated 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)
useless <- mapply(write.pdb, pdb.resid, file.names)

Run the code above in your browser using DataLab