def short_dna(): """ Build a system that contains a short DNA double strand without edges. """ molecule = read_pdb(SHORT_DNA) system = vermouth.system.System() system.molecules = [molecule] return system
def test_run_dssp_input_file(tmpdir, caplog, pdb, loglevel, expected): """ Test that the DSSP input file is preserved (only) in the right conditions """ caplog.set_level(loglevel) system = vermouth.System() for molecule in read_pdb(str(pdb)): system.add_molecule(molecule) with tmpdir.as_cwd(): try: dssp.run_dssp(system, executable=DSSP_EXECUTABLE) except DSSPError: pass if expected: target = 1 else: target = 0 matches = glob.glob('dssp_in*.pdb') assert len(matches) == target, matches if matches: # Make sure it's a valid PDB file. Mostly anyway. list(read_pdb(matches[0]))
def test_filter_minimal(): """ Test that :func:`vermouth.selectors.filter_minimal` works as expected. """ # Build a molecule that has all even atoms with no positions. molecule = read_pdb(str(PDB_PROTEIN)) for atom in list(molecule.nodes.values())[::2]: atom['position'] = None # This means that we want to keep the odd atoms to_keep = list(molecule.nodes)[1::2] filtered = vermouth.selectors.filter_minimal( molecule, selector=vermouth.selectors.selector_has_position) # Do we keep the right atoms? assert list(filtered) == to_keep
def test_run_dssp(savefile, tmpdir): """ Test that :func:`vermouth.molecule.dssp.dssp.run_dssp` runs as expected and generate a save file only if requested. """ # The test runs twice, once with the savefile set to True so we test with # saving the DSSP output to file, and once with savefile set t False so we # do not generate the file. The "savefile" argument is set by # pytest.mark.parametrize. # The "tmpdir" argument is set by pytest and is the path to a temporary # directory that exists only for one iteration of the test. if savefile: path = tmpdir.join('dssp_output') else: path = None system = vermouth.System() for molecule in read_pdb(str(PDB_PROTEIN)): system.add_molecule(molecule) secondary_structure = dssp.run_dssp(system, executable=DSSP_EXECUTABLE, savefile=path) # Make sure we produced the expected sequence of secondary structures assert secondary_structure == SECSTRUCT_1BTA # If we test with savefile, then we need to make sure the file is created # and its content corresponds to the reference (excluding the first lines # that are variable or contain non-essencial data read from the PDB file). # If we test without savefile, then we need to make sure the file is not # created. if savefile: DeferredFileWriter().write() assert path.exists() with open(str(path)) as genfile, open(str(DSSP_OUTPUT)) as reffile: # DSSP 3 is outputs mostly the same thing as DSSP2, though there # are some differences in non significant whitespaces, and an extra # field header. We need to normalize these differences to be able # to compare. gen = '\n'.join([ line.strip().replace(' CHAIN', '') for line in genfile.readlines()[6:] ]) ref = '\n'.join([line.strip() for line in reffile.readlines()[6:]]) assert gen == ref else: # Is the directory empty? assert not os.listdir(str(tmpdir))
def cys_protein(): """ Read a PDB file describing a protein with a cystein bridge and cystein residues that are not involved in a bridge. Embed the content of the PDB in a :class:`vermouth.system.System`. Note that the PDB file does contain water, ions, and ligands in addition to the protein. The ligand bonds are explicitely provided as CONECT records. The edges from the CONECT records are removed from the system, so there is no edge left. """ molecule = read_pdb(PDB_CYS) molecule.remove_edges_from(list(molecule.edges)) system = vermouth.system.System() system.molecules = [molecule] assert len(system.molecules[0].edges) == 0 return system
def test_run_dssp(savefile, tmpdir): """ Test that :func:`vermouth.molecule.dssp.dssp.run_dssp` runs as expected and generate a save file only if requested. """ # The test runs twice, once with the savefile set to True so we test with # savinf the DSSP output to file, and once with savefile set t False so we # do not generate the file. The "savefile" argument is set by # pytest.mark.parametrize. # The "tmpdir" argument is set by pytest and is the path to a temporary # directory that exists only for one iteration of the test. if savefile: path = tmpdir.join('dssp_output') else: path = None system = vermouth.System() system.add_molecule(read_pdb(str(PDB_PROTEIN))) secondary_structure = dssp.run_dssp(system, executable=DSSP_EXECUTABLE, savefile=path) # Make sure we produced the expected sequence of secondary structures assert secondary_structure == SECSTRUCT_1BTA # If we test with savefile, then we need to make sure the file is created # and its content corresponds to the reference (excluding the first lines # that are variable or contain non-essencial data read from the PDB file). # If we test without savefile, then we need to make sure the file is not # created. if savefile: assert path.exists() with open(str(path)) as genfile, open(str(DSSP_OUTPUT)) as reffile: gen = '\n'.join(genfile.readlines()[6:]) ref = '\n'.join(reffile.readlines()[6:]) assert gen == ref else: # Is the directory empty? assert not os.listdir(str(tmpdir))
import functools import pytest import vermouth from vermouth.pdb.pdb import read_pdb from vermouth.tests.datafiles import ( PDB_PROTEIN, PDB_NOT_PROTEIN, PDB_PARTIALLY_PROTEIN, ) @pytest.mark.parametrize('molecules, reference_answer', [(read_pdb(str(path)), answer) for path, answer in [ (PDB_PROTEIN, True), (PDB_NOT_PROTEIN, False), (PDB_PARTIALLY_PROTEIN, False), ]]) def test_is_protein(molecules, reference_answer): """ Make sure that proteins are correctly identified as such. """ assert len(molecules) == 1 molecule = molecules[0] assert vermouth.selectors.is_protein(molecule) == reference_answer @pytest.mark.parametrize('atom, reference_answer', ( ({