-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f41b4ec
commit e4b29ce
Showing
5 changed files
with
528 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,103 @@ | ||
import warnings | ||
import pandas as pd | ||
import pytest | ||
|
||
import MDAnalysis as mda | ||
from typing import Literal, get_args | ||
|
||
from prolint2 import Universe | ||
from prolint2.core.groups import ExtendedAtomGroup | ||
from prolint2.sampledata import GIRKDataSample, COX1DataSample, SMODataSample | ||
|
||
GIRK = GIRKDataSample() | ||
COX1 = COX1DataSample() | ||
SMO = SMODataSample() | ||
|
||
warnings.filterwarnings("ignore") | ||
|
||
TimeUnitLiteral = Literal["fs", "ps", "ns", "us", "ms", "s"] | ||
|
||
# Build VALID_UNITS from TimeUnitLiteral | ||
VALID_UNITS = get_args(TimeUnitLiteral) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def universes(): | ||
return [ | ||
Universe(GIRK.coordinates, GIRK.trajectory), | ||
Universe(COX1.coordinates, COX1.trajectory), | ||
Universe(SMO.coordinates, SMO.trajectory), | ||
] | ||
|
||
|
||
class TestUniverse: | ||
def test_init_with_universe(self, universes): | ||
for u in universes: | ||
assert isinstance(u, Universe) | ||
assert isinstance(u, mda.Universe) | ||
|
||
def test_query_property(self, universes): | ||
for u in universes: | ||
assert u.query is not None | ||
assert isinstance(u.query, ExtendedAtomGroup) | ||
|
||
def test_database_property(self, universes): | ||
for u in universes: | ||
assert u.database is not None | ||
assert isinstance(u.database, ExtendedAtomGroup) | ||
|
||
def test_compute_contacts(self, universes): | ||
dict_of_contacts = {0: GIRK, 1: COX1, 2: SMO} | ||
for i, u in enumerate(universes): | ||
contacts = u.compute_contacts(cutoff=7) | ||
calc_df = contacts.create_dataframe(u.trajectory.n_frames) | ||
ref_df = pd.read_csv(dict_of_contacts[i].contacts, index_col=[0, 1]) | ||
ref_df.columns = ref_df.columns.astype(int) | ||
ref_df = ref_df.astype("int8") | ||
pd.testing.assert_frame_equal(calc_df, ref_df) | ||
|
||
def test_load_contacts_from_file(self, universes): | ||
dict_of_contacts = {0: GIRK, 1: COX1, 2: SMO} | ||
for i, u in enumerate(universes): | ||
contacts = u.load_contacts_from_file(dict_of_contacts[i].contacts) | ||
calc_df = contacts.create_dataframe(u.trajectory.n_frames) | ||
ref_df = pd.read_csv(dict_of_contacts[i].contacts, index_col=[0, 1]) | ||
ref_df.columns = ref_df.columns.astype(int) | ||
ref_df = ref_df.astype("int8") | ||
pd.testing.assert_frame_equal(calc_df, ref_df) | ||
|
||
def test_units_property(self, universes): | ||
for u in universes: | ||
assert u.units in VALID_UNITS | ||
|
||
def test_units_property_setter(self, universes): | ||
for u in universes: | ||
new_units = "ns" | ||
u.units = new_units | ||
assert u.units == new_units | ||
assert u.units in VALID_UNITS | ||
|
||
def test_normalize_by_property(self, universes): | ||
for u in universes: | ||
assert u.normalize_by in ["counts", "actual_time", "time_fraction"] | ||
|
||
def test_normalize_by_property_setter(self, universes): | ||
for u in universes: | ||
new_normalize_by = "counts" | ||
u.normalize_by = new_normalize_by | ||
assert u.normalize_by == new_normalize_by | ||
assert u.normalize_by in ["counts", "actual_time", "time_fraction"] | ||
|
||
def test_query_property_setter(self, universes): | ||
for u in universes: | ||
new_query = u.select_atoms("protein and (name CA or name BB)") | ||
u.query = new_query | ||
assert u.query is not None | ||
assert isinstance(u.query, ExtendedAtomGroup) | ||
|
||
def test_database_property_setter(self, universes): | ||
for u in universes: | ||
new_database = u.select_atoms("resname CHOL or resname CHL1") | ||
u.database = new_database | ||
assert u.database is not None | ||
assert isinstance(u.database, ExtendedAtomGroup) | ||
# import warnings | ||
# import pandas as pd | ||
# import pytest | ||
|
||
# import MDAnalysis as mda | ||
# from typing import Literal, get_args | ||
|
||
# from prolint2 import Universe | ||
# from prolint2.core.groups import ExtendedAtomGroup | ||
# from prolint2.sampledata import GIRKDataSample, COX1DataSample, SMODataSample | ||
|
||
# GIRK = GIRKDataSample() | ||
# COX1 = COX1DataSample() | ||
# SMO = SMODataSample() | ||
|
||
# warnings.filterwarnings("ignore") | ||
|
||
# TimeUnitLiteral = Literal["fs", "ps", "ns", "us", "ms", "s"] | ||
|
||
# # Build VALID_UNITS from TimeUnitLiteral | ||
# VALID_UNITS = get_args(TimeUnitLiteral) | ||
|
||
|
||
# @pytest.fixture(scope="module") | ||
# def universes(): | ||
# return [ | ||
# Universe(GIRK.coordinates, GIRK.trajectory), | ||
# Universe(COX1.coordinates, COX1.trajectory), | ||
# Universe(SMO.coordinates, SMO.trajectory), | ||
# ] | ||
|
||
|
||
# class TestUniverse: | ||
# def test_init_with_universe(self, universes): | ||
# for u in universes: | ||
# assert isinstance(u, Universe) | ||
# assert isinstance(u, mda.Universe) | ||
|
||
# def test_query_property(self, universes): | ||
# for u in universes: | ||
# assert u.query is not None | ||
# assert isinstance(u.query, ExtendedAtomGroup) | ||
|
||
# def test_database_property(self, universes): | ||
# for u in universes: | ||
# assert u.database is not None | ||
# assert isinstance(u.database, ExtendedAtomGroup) | ||
|
||
# def test_compute_contacts(self, universes): | ||
# dict_of_contacts = {0: GIRK, 1: COX1, 2: SMO} | ||
# for i, u in enumerate(universes): | ||
# contacts = u.compute_contacts(cutoff=7) | ||
# calc_df = contacts.create_dataframe(u.trajectory.n_frames) | ||
# ref_df = pd.read_csv(dict_of_contacts[i].contacts, index_col=[0, 1]) | ||
# ref_df.columns = ref_df.columns.astype(int) | ||
# ref_df = ref_df.astype("int8") | ||
# pd.testing.assert_frame_equal(calc_df, ref_df) | ||
|
||
# def test_load_contacts_from_file(self, universes): | ||
# dict_of_contacts = {0: GIRK, 1: COX1, 2: SMO} | ||
# for i, u in enumerate(universes): | ||
# contacts = u.load_contacts_from_file(dict_of_contacts[i].contacts) | ||
# calc_df = contacts.create_dataframe(u.trajectory.n_frames) | ||
# ref_df = pd.read_csv(dict_of_contacts[i].contacts, index_col=[0, 1]) | ||
# ref_df.columns = ref_df.columns.astype(int) | ||
# ref_df = ref_df.astype("int8") | ||
# pd.testing.assert_frame_equal(calc_df, ref_df) | ||
|
||
# def test_units_property(self, universes): | ||
# for u in universes: | ||
# assert u.units in VALID_UNITS | ||
|
||
# def test_units_property_setter(self, universes): | ||
# for u in universes: | ||
# new_units = "ns" | ||
# u.units = new_units | ||
# assert u.units == new_units | ||
# assert u.units in VALID_UNITS | ||
|
||
# def test_normalize_by_property(self, universes): | ||
# for u in universes: | ||
# assert u.normalize_by in ["counts", "actual_time", "time_fraction"] | ||
|
||
# def test_normalize_by_property_setter(self, universes): | ||
# for u in universes: | ||
# new_normalize_by = "counts" | ||
# u.normalize_by = new_normalize_by | ||
# assert u.normalize_by == new_normalize_by | ||
# assert u.normalize_by in ["counts", "actual_time", "time_fraction"] | ||
|
||
# def test_query_property_setter(self, universes): | ||
# for u in universes: | ||
# new_query = u.select_atoms("protein and (name CA or name BB)") | ||
# u.query = new_query | ||
# assert u.query is not None | ||
# assert isinstance(u.query, ExtendedAtomGroup) | ||
|
||
# def test_database_property_setter(self, universes): | ||
# for u in universes: | ||
# new_database = u.select_atoms("resname CHOL or resname CHL1") | ||
# u.database = new_database | ||
# assert u.database is not None | ||
# assert isinstance(u.database, ExtendedAtomGroup) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,81 @@ | ||
import warnings | ||
import pytest | ||
import numpy as np | ||
from collections import defaultdict | ||
# import warnings | ||
# import pytest | ||
# import numpy as np | ||
# from collections import defaultdict | ||
|
||
import MDAnalysis as mda | ||
from prolint2 import Universe | ||
from prolint2.sampledata import GIRKDataSample, COX1DataSample, SMODataSample | ||
from prolint2.computers.contacts import SerialContacts | ||
# import MDAnalysis as mda | ||
# from prolint2 import Universe | ||
# from prolint2.sampledata import GIRKDataSample, COX1DataSample, SMODataSample | ||
# from prolint2.computers.contacts import SerialContacts | ||
|
||
GIRK = GIRKDataSample() | ||
COX1 = COX1DataSample() | ||
SMO = SMODataSample() | ||
# GIRK = GIRKDataSample() | ||
# COX1 = COX1DataSample() | ||
# SMO = SMODataSample() | ||
|
||
warnings.filterwarnings("ignore") | ||
# warnings.filterwarnings("ignore") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def universes(): | ||
return [ | ||
Universe(GIRK.coordinates, GIRK.trajectory), | ||
Universe(COX1.coordinates, COX1.trajectory), | ||
Universe(SMO.coordinates, SMO.trajectory), | ||
] | ||
# @pytest.fixture(scope="module") | ||
# def universes(): | ||
# return [ | ||
# Universe(GIRK.coordinates, GIRK.trajectory), | ||
# Universe(COX1.coordinates, COX1.trajectory), | ||
# Universe(SMO.coordinates, SMO.trajectory), | ||
# ] | ||
|
||
|
||
class TestSerialContacts: | ||
def test_init(self, universes): | ||
for u in universes: | ||
cutoff = 6.0 | ||
contacts = SerialContacts(u, u.query, u.database, cutoff) | ||
assert contacts.query == u.query | ||
assert contacts.database == u.database | ||
assert contacts.cutoff == cutoff | ||
assert len(contacts.q_resids) == len(u.query.resids) | ||
assert len(contacts.db_resids) == len(u.database.resids) | ||
assert len(contacts.db_resnames) == len(u.database.resnames) | ||
assert contacts.contacts is None | ||
assert isinstance(contacts.contact_frames, defaultdict) | ||
# class TestSerialContacts: | ||
# def test_init(self, universes): | ||
# for u in universes: | ||
# cutoff = 6.0 | ||
# contacts = SerialContacts(u, u.query, u.database, cutoff) | ||
# assert contacts.query == u.query | ||
# assert contacts.database == u.database | ||
# assert contacts.cutoff == cutoff | ||
# assert len(contacts.q_resids) == len(u.query.resids) | ||
# assert len(contacts.db_resids) == len(u.database.resids) | ||
# assert len(contacts.db_resnames) == len(u.database.resnames) | ||
# assert contacts.contacts is None | ||
# assert isinstance(contacts.contact_frames, defaultdict) | ||
|
||
def test_init_invalid_selection(self): | ||
with pytest.raises(mda.exceptions.SelectionError): | ||
universe = Universe(GIRK.coordinates, GIRK.trajectory) | ||
query = universe.select_atoms("not protein") | ||
database = universe.select_atoms("lipid") | ||
SerialContacts(universe, query, database) | ||
# def test_init_invalid_selection(self): | ||
# with pytest.raises(mda.exceptions.SelectionError): | ||
# universe = Universe(GIRK.coordinates, GIRK.trajectory) | ||
# query = universe.select_atoms("not protein") | ||
# database = universe.select_atoms("lipid") | ||
# SerialContacts(universe, query, database) | ||
|
||
def test_init_invalid_cutoff(self): | ||
with pytest.raises(ValueError): | ||
universe = Universe(GIRK.coordinates, GIRK.trajectory) | ||
cutoff = -2.0 | ||
SerialContacts(universe, universe.query, universe.database, cutoff) | ||
# def test_init_invalid_cutoff(self): | ||
# with pytest.raises(ValueError): | ||
# universe = Universe(GIRK.coordinates, GIRK.trajectory) | ||
# cutoff = -2.0 | ||
# SerialContacts(universe, universe.query, universe.database, cutoff) | ||
|
||
def test_validate_inputs(self, universes): | ||
for u in universes: | ||
contacts = SerialContacts(u, u.query, u.database) | ||
contacts._validate_inputs() # No exception should be raised | ||
# def test_validate_inputs(self, universes): | ||
# for u in universes: | ||
# contacts = SerialContacts(u, u.query, u.database) | ||
# contacts._validate_inputs() # No exception should be raised | ||
|
||
query_empty = u.select_atoms("protein and name XYZ") | ||
with pytest.raises(ValueError): | ||
SerialContacts(u, query_empty, u.database) | ||
# query_empty = u.select_atoms("protein and name XYZ") | ||
# with pytest.raises(ValueError): | ||
# SerialContacts(u, query_empty, u.database) | ||
|
||
cutoff_zero = 0.0 | ||
with pytest.raises(ValueError): | ||
SerialContacts(u, u.query, u.database, cutoff_zero) | ||
# cutoff_zero = 0.0 | ||
# with pytest.raises(ValueError): | ||
# SerialContacts(u, u.query, u.database, cutoff_zero) | ||
|
||
def test_get_residue_lipid_info(self, universes): | ||
for u in universes: | ||
contacts = SerialContacts(u, u.query, u.database) | ||
pair = (0, 1) | ||
residue_id, lipid_id, lipid_name = contacts._get_residue_lipid_info(pair) | ||
assert isinstance(residue_id, np.int64) | ||
assert isinstance(lipid_id, np.int64) | ||
assert isinstance(lipid_name, str) | ||
# def test_get_residue_lipid_info(self, universes): | ||
# for u in universes: | ||
# contacts = SerialContacts(u, u.query, u.database) | ||
# pair = (0, 1) | ||
# residue_id, lipid_id, lipid_name = contacts._get_residue_lipid_info(pair) | ||
# assert isinstance(residue_id, np.int64) | ||
# assert isinstance(lipid_id, np.int64) | ||
# assert isinstance(lipid_name, str) | ||
|
||
def test_compute_pairs(self, universes): | ||
for u in universes: | ||
contacts = SerialContacts(u, u.query, u.database) | ||
pairs = contacts._compute_pairs() | ||
assert isinstance(pairs, np.ndarray) | ||
assert pairs.shape[1] == 2 | ||
# def test_compute_pairs(self, universes): | ||
# for u in universes: | ||
# contacts = SerialContacts(u, u.query, u.database) | ||
# pairs = contacts._compute_pairs() | ||
# assert isinstance(pairs, np.ndarray) | ||
# assert pairs.shape[1] == 2 |
Oops, something went wrong.