def test_empty_frames(self):
        """
        Tests that the multithreading doesnt discard a fragment when no contacts are found in the first frame
        (see issue #38).
        """
        outfile = "tests/5xnd_contacts.tsv"
        argv = [
            "--topology", "tests/5xnd_topology.pdb", "--trajectory",
            "tests/5xnd_trajectory.dcd", "--itypes", "sb", "--sele",
            "resname ASP LYS", "--output", outfile
        ]
        get_dynamic_contacts.main(argv=argv)

        self.assertTrue(os.path.exists(outfile))
        with open(outfile) as f:
            lines = f.readlines()
            self.assertEqual(len(lines), 22)

            # Check that first two lines are comments
            self.assertEqual(lines[0][0], "#")
            self.assertEqual(lines[1][0], "#")
            self.assertEqual(lines[2][0], "1")

            # Check that 12 frames total are generated
            frames = set([int(l.split()[0]) for l in lines[2:]])
            self.assertEqual(frames,
                             set([1, 2, 3, 4, 5, 8, 12, 13, 15, 16, 18, 19]))

        os.remove(outfile)
    def test_5xnd_nolabel(self):
        """
        Take the 5xnd trajectory, compute contacts and then use TICC to extract two sets of frequencies
        """
        top_file = "tests/5xnd_topology.pdb"
        trj_file = "tests/5xnd_trajectory.dcd"
        contact_file = "tests/5xnd_contacts.tsv"
        args = "--topology %s --trajectory %s --output %s --itypes all" % (
            top_file, trj_file, contact_file)
        get_dynamic_contacts.main(argv=args.split(" "))
        self.assertTrue(os.path.exists(contact_file))

        ticc_output = ("tests/5xnd_segments.txt", "tests/5xnd_ticc")
        args = "--input_contacts %s --clusters 2 --tab_output %s --frequency_output %s" % \
               ((contact_file,) + ticc_output)
        get_contact_ticc.main(argv=args.split(" "))
        ticc_output = (ticc_output[0],
                       "tests/5xnd_ticc_resfreq_cluster000.tsv",
                       "tests/5xnd_ticc_resfreq_cluster001.tsv")

        for output_file in ticc_output:
            self.assertTrue(os.path.exists(output_file))

        for output_file in ticc_output:
            os.remove(output_file)
        os.remove(contact_file)
    def test_5xnd_nolabel(self):
        contact_file = "tests/5xnd_contacts.tsv"
        argv = ("--topology tests/5xnd_topology.pdb "
                "--trajectory tests/5xnd_trajectory.dcd "
                "--output " + contact_file + " "
                "--itypes all").split(" ")
        get_dynamic_contacts.main(argv=argv)
        self.assertTrue(os.path.exists(contact_file))

        flare_file = "tests/5xnd_timeflare.json"
        argv = ("--input " + contact_file + " "
                "--output " + flare_file).split(" ")
        get_contact_flare.main(argv=argv)

        self.assertTrue(os.path.exists(flare_file))

        # TODO: test contents of flare_file

        os.remove(contact_file)
        os.remove(flare_file)
    def test_5xnd(self):
        outfile = "tests/5xnd_contacts.tsv"
        argv = ("--topology tests/5xnd_topology.pdb "
                "--trajectory tests/5xnd_trajectory.dcd "
                "--output " + outfile + " "
                "--itypes all").split(" ")
        get_dynamic_contacts.main(argv=argv)

        self.assertTrue(os.path.exists(outfile))
        with open(outfile) as f:
            lines = f.readlines()
            self.assertEqual(len(lines), 20283)

            # Check that first two lines are comments
            self.assertEqual(lines[0][0], "#")
            self.assertEqual(lines[1][0], "#")
            self.assertEqual(lines[2][0], "0")

            # Check that 20 frames total are generated
            frames = set([int(l.split()[0]) for l in lines[2:]])
            self.assertEqual(frames, set(range(20)))

            # Check that there are no duplicate interactions, even if atom pairs are swapped
            contact_hashes = set()
            for line in lines[2:]:
                tokens = line.strip().split("\t")
                a1 = tokens[2]
                a2 = tokens[3]
                if a2 < a1:
                    a1, a2 = a2, a1
                chash = "\t".join(tokens[0:2] + [a1, a2])
                if chash in contact_hashes:
                    print(chash)
                self.assertFalse(chash in contact_hashes)
                contact_hashes.add(chash)

        os.remove(outfile)
Exemple #5
0
#!/usr/bin/env python3

import get_dynamic_contacts
import os

if __name__ == "__main__":
    get_dynamic_contacts.main(traj_required=False)

    # Suppress stdout from vmd as program terminates
    devnull = open('/dev/null', "w")
    os.dup2(devnull.fileno(), 1)