Esempio n. 1
0
    def test_multiple_references(self):
        """
        Test if it works with several reference atoms in the same residue.
        """
        # Split the bilayer using POPC:P1 and POPC:C12 as reference atoms
        path = os.path.join(REFDIR, "membrane.gro")
        axis = "z"
        select_code = [("POPC", "P1"), ("POPC", "C12")]
        with open(path) as infile:
            atoms = list(splitleafs.read_gro(infile))
        print(len(atoms))
        selection = list(splitleafs.select_atoms(atoms, select_code))
        print(len(selection))
        coordinates = splitleafs.axis_coordinates(selection, axis)
        average = splitleafs.mean(coordinates)
        groups = splitleafs.split_get_res(atoms, average, axis, select_code)

        # The resulting groups should be the exact same as the one from the
        # reference output built with just POPC:P1 as reference atom
        ndx_reference = os.path.join(REFDIR, "leafs.ndx")
        with open(ndx_reference) as infile:
            reference = read_ndx(infile)
        for key, value in reference.items():
            self.assertEqual(value, groups[key],
                             ("The {0} group is different between the "
                              "function output and the reference.")
                             .format(key))
Esempio n. 2
0
    def test_split_get_res(self):
        """
        Test if the group formed by the split_get_res function are consistent.
        """
        # Split the bilayer
        path = os.path.join(REFDIR, "membrane.gro")
        axis = "z"
        with open(path) as infile:
            atoms = list(splitleafs.read_gro(infile))
        selection = list(splitleafs.select_atoms(atoms, [("P1",)]))
        coordinates = splitleafs.axis_coordinates(selection, axis)
        average = splitleafs.mean(coordinates)
        groups = splitleafs.split_get_res(atoms, average, axis, [("P1",)])

        # Do the group have the right size?
        natoms_popc = sum((1 for atom in atoms if atom["resname"] == "POPC"))
        print("natom_popc: {0}".format(natoms_popc))
        for key, value in groups.items():
            self.assertEqual(len(value) * 2, natoms_popc,
                             ("The {0} group contains {1} atoms it should "
                              "contain {2} ones.")
                             .format(key, len(value), natoms_popc // 2))

        # Is there doubles in the groups?
        for key, value in groups.items():
            self.assertEqual(len(value), len(set(value)),
                             "There is double values in the {0} group."
                             .format(key))

        # Is the group sorted? A group can not be sorted if the input file
        # is not but the test input file is correctly sorted.
        for key, value in groups.items():
            ordered = value[:]
            ordered.sort()
            self.assertEqual(value, ordered,
                             "The {0} group is nor correctly ordered."
                             .format(key))

        # Are the groups the same as the reference?
        ndx_reference = os.path.join(REFDIR, "leafs.ndx")
        with open(ndx_reference) as infile:
            reference = read_ndx(infile)
        for key, value in reference.items():
            self.assertEqual(value, groups[key],
                             ("The {0} group is different between the "
                              "function output and the reference.")
                             .format(key))