PLS and OPLS regressors
Project description
OPLS
OPLS and PLS regressors
Installation
Run
pip install .
Usage
Given a structure file and trajectory as struct.pdb
and traj.xtc
we can e.g. define a function as the distance of two specific C alpha atoms:
import MDAnalysis as mda
import numpy as np
# Make universe and load trajectory to memory
u = mda.Universe("struct.pdb","traj.xtc")
coords = np.array([u.atoms.positions.copy() for ts in u.trajectory])
# Calculate function as distance between res 2 and 150 CA
sel = u.select_atoms("resid 2 150 and name CA")
y = np.linalg.norm(coords[:,sel.indices[0],:]-coords[:,sel.indices[1],:], axis=-1)
# Flatten from N by M by 3 dimensions to N by 3M
X = coords.reshape((coords.shape[0],-1))
Now that we have shape N by 3M array of X values and a one dimensional y, we can start running the OPLS
from OPLS import PLS, OPLS
opls = OPLS(n_components=1).fit(X,y)
This will fit a one component OPLS model on the data. To get a new X array, where we have filtered out the orthogonal components, we can use the transform function
X_filt = opls.transform(X)
Finally to get our model, we can fit the PLS with the filtered data.
pls = PLS(n_components=5).fit(X_filt,y)
If we have a new set of data, called X_new
, we can predict the y values for it as
X_new_filt = opls.transform(X_new)
y_new_predicted = pls.predict(X_new_filt)
or if the corresponding y_new
are known, we can estimate the coefficient of determination (r2
) with
X_new_filt = opls.transform(X_new)
r2 = pls.score(X_new_filt, y_new)
Having to run two separate models one after the other can be tiresome, so the package also includes as OPLS_PLS
object, which does the above much easier:
from OPLS import OPLS_PLS
# Fitting:
opls_pls = OPLS_PLS(n_components=1,pls_components=5).fit(X,y)
# Predicting:
y_new_predicted = opls_pls.predict(X_new)
# Scoring:
r2 = opls_pls.score(X_new, y_new)
References
Main references for OPLS:
[1] Wold S, et al. PLS-regression: a basic tool of chemometrics.
Chemometr Intell Lab Sys 2001, 58, 109–130.
[2] Bylesjo M, et al. Model Based Preprocessing and Background
Elimination: OSC, OPLS, and O2PLS. in Comprehensive Chemometrics.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file OPLS-MD-0.0.1.tar.gz
.
File metadata
- Download URL: OPLS-MD-0.0.1.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd84984fd9a80e260750e1b15dcec6ede8544cdc2b291244971d3db50241fe48 |
|
MD5 | 70752977ced0cb4ac645c1678afe1a55 |
|
BLAKE2b-256 | 49d0820310d6bb4d7c55cd132b5084596bda52b47aefb4ffa6ea3fcb3e7b95b0 |
File details
Details for the file OPLS_MD-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: OPLS_MD-0.0.1-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51b6fa60497abe482d5da8f6ed9857bb336ce68a4751cdb3eb1a69ccb5506d97 |
|
MD5 | d7e7e4e0157cab04c160b957a3fe026f |
|
BLAKE2b-256 | ad8d1b94a9310283fa7640464726b540926d0ed9b5f45538e61fefd165ed5c44 |