File: test_removechains.py

package info (click to toggle)
python-pdbfixer 1.9-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,752 kB
  • sloc: xml: 4,240; python: 1,459; sh: 47; makefile: 19
file content (37 lines) | stat: -rw-r--r-- 1,647 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import openmm.app as app
import pdbfixer
import tempfile
import time
from pathlib import Path

from urllib.request import urlopen
from io import StringIO

import pytest

@pytest.fixture(scope="module")
def file_content():
    return (Path(__file__).parent / "data" / "4JSV.pdb").read_text()

def remove_chains_and_verify(file_content, expected_chain_ids_remaining, **kws):
    # Create a PDBFixer instance for the given pdbid
    fixer = pdbfixer.PDBFixer(pdbfile=StringIO(file_content))
    # Remove specified chains.
    fixer.removeChains(**kws)
    # Check to make sure asserted chains remain.
    chain_ids_remaining = [c.id for c in fixer.topology.chains()]
    assert expected_chain_ids_remaining == chain_ids_remaining

def test_removechain_ids(file_content):
    remove_chains_and_verify(file_content, ['B', 'D', 'A', 'C', 'B', 'A'], chainIds=[])
    remove_chains_and_verify(file_content, ['A', 'C', 'A'], chainIds=['B', 'D'])
    remove_chains_and_verify(file_content, ['B', 'D', 'B'], chainIds=['A', 'C'])
    remove_chains_and_verify(file_content, ['D', 'C'], chainIds=['B', 'A'])
    remove_chains_and_verify(file_content, [], chainIds=['B', 'D', 'A', 'C'])

def test_removechain_indices(file_content):
    remove_chains_and_verify(file_content, ['B', 'D', 'A', 'C', 'B', 'A'], chainIndices=[])
    remove_chains_and_verify(file_content, ['A', 'C', 'B', 'A'], chainIndices=[0, 1])
    remove_chains_and_verify(file_content, ['B', 'D', 'B', 'A'], chainIndices=[2, 3])
    remove_chains_and_verify(file_content, ['D', 'C', 'B', 'A'], chainIndices=[0, 2])
    remove_chains_and_verify(file_content, [], chainIndices=[0, 1, 2, 3, 4, 5])