def test_load_bonds_from_pdb(self):
        """
    TestPDB: Verifies that bonds can be loaded from PDB.
    """
        pdb = PDB()
        # Test that we can load CO2
        carbon_atom = Atom(element="C")
        oxygen_atom_1 = Atom(element="O")
        oxygen_atom_2 = Atom(element="O")

        pdb.add_new_atom(carbon_atom)
        pdb.add_new_atom(oxygen_atom_1)
        pdb.add_new_atom(oxygen_atom_2)
        lines = [
            "CONECT    1    2    3                                                 "
            "CONECT    2                                                           "
            "CONECT    3                                                           "
        ]
        with tempfile.NamedTemporaryFile() as temp:
            temp.write("\n".join(lines))
            temp.flush()
            pdb.load_bonds_from_pdb(temp.name)
        assert len(carbon_atom.indices_of_atoms_connecting) == 2
        assert len(oxygen_atom_1.indices_of_atoms_connecting) == 0
        assert len(oxygen_atom_2.indices_of_atoms_connecting) == 0
 def setUp(self):
     """
 Instantiates a pair of atom objects for tests.
 """
     self.empty_atom = Atom()
     self.trial_atom = Atom()
     self.trial_atom.atomname = "C"
     self.trial_atom.coordinates = Point(coords=np.array([1, 2, 3]))
     self.trial_atom.charge = 0.0
     self.trial_atom.element = "C"
     self.trial_atom.residue = "CYS"
     # TODO(bramsundar): Fill in a non-junk value for chain.
     self.trial_atom.chain = "FF"
     self.trial_atom.indices_of_atoms_connecting = [4, 5, 6]
 def setUp(self):
     """
 Instantiates a pair of atom objects for tests.
 """
     self.empty_atom = Atom()
     self.trial_atom = Atom()
     self.trial_atom.atomname = "C"
     self.trial_atom.coordinates = Point(coords=np.array([1, 2, 3]))
     self.trial_atom.charge = 0.
     self.trial_atom.element = "C"
     self.trial_atom.residue = "CYS"
     # TODO(bramsundar): Fill in a non-junk value for chain.
     self.trial_atom.chain = "FF"
     self.trial_atom.indices_of_atoms_connecting = [4, 5, 6]
class TestAtom(unittest.TestCase):
    """
  Test atom class.
  """

    def setUp(self):
        """
    Instantiates a pair of atom objects for tests.
    """
        self.empty_atom = Atom()
        self.trial_atom = Atom()
        self.trial_atom.atomname = "C"
        self.trial_atom.coordinates = Point(coords=np.array([1, 2, 3]))
        self.trial_atom.charge = 0.0
        self.trial_atom.element = "C"
        self.trial_atom.residue = "CYS"
        # TODO(bramsundar): Fill in a non-junk value for chain.
        self.trial_atom.chain = "FF"
        self.trial_atom.indices_of_atoms_connecting = [4, 5, 6]

    def test_copy_of(self):
        """
    TestAtom: Verify that copy_of preserves atom information.
    """
        copy_atom = self.trial_atom.copy_of()
        assert copy_atom.atomname == "C"
        assert np.array_equal(copy_atom.coordinates.as_array(), np.array([1, 2, 3]))
        assert copy_atom.charge == 0
        assert copy_atom.element == "C"
        assert copy_atom.residue == "CYS"
        assert copy_atom.chain == "FF"
        assert copy_atom.indices_of_atoms_connecting == [4, 5, 6]

    def test_create_pdb_line(self):
        """
    TestAtom: Verify that PDB Line is in correct format.
    """
        # TODO(bramsundar): Add a more nontrivial test after looking into
        # PDB standard.
        line = self.trial_atom.create_pdb_line(1)
        assert type(line) == str

    def test_number_of_neighors(self):
        """
    TestAtom: Verify that the number of neighbors is computed correctly.
    """
        assert self.empty_atom.number_of_neighbors() == 0
        assert self.trial_atom.number_of_neighbors() == 3
class TestAtom(unittest.TestCase):
    """
  Test atom class.
  """
    def setUp(self):
        """
    Instantiates a pair of atom objects for tests.
    """
        self.empty_atom = Atom()
        self.trial_atom = Atom()
        self.trial_atom.atomname = "C"
        self.trial_atom.coordinates = Point(coords=np.array([1, 2, 3]))
        self.trial_atom.charge = 0.
        self.trial_atom.element = "C"
        self.trial_atom.residue = "CYS"
        # TODO(bramsundar): Fill in a non-junk value for chain.
        self.trial_atom.chain = "FF"
        self.trial_atom.indices_of_atoms_connecting = [4, 5, 6]

    def test_copy_of(self):
        """
    TestAtom: Verify that copy_of preserves atom information.
    """
        copy_atom = self.trial_atom.copy_of()
        assert copy_atom.atomname == "C"
        assert np.array_equal(copy_atom.coordinates.as_array(),
                              np.array([1, 2, 3]))
        assert copy_atom.charge == 0
        assert copy_atom.element == "C"
        assert copy_atom.residue == "CYS"
        assert copy_atom.chain == "FF"
        assert copy_atom.indices_of_atoms_connecting == [4, 5, 6]

    def test_create_pdb_line(self):
        """
    TestAtom: Verify that PDB Line is in correct format.
    """
        # TODO(bramsundar): Add a more nontrivial test after looking into
        # PDB standard.
        line = self.trial_atom.create_pdb_line(1)
        assert type(line) == str

    def test_number_of_neighors(self):
        """
    TestAtom: Verify that the number of neighbors is computed correctly.
    """
        assert self.empty_atom.number_of_neighbors() == 0
        assert self.trial_atom.number_of_neighbors() == 3
 def test_add_new_atom(self):
     """
 TestPDB: Verifies that new atoms can be added.
 """
     # Verify that no atoms are present when we start.
     assert len(self.pdb.all_atoms.keys()) == 0
     empty_atom = Atom()
     self.pdb.add_new_atom(empty_atom)
     # Verify that we now have one atom
     assert len(self.pdb.all_atoms.keys()) == 1
 def test_metallic_charges(self):
     """
 TestPDB: Verify that non-protein charges are assigned properly.
 """
     # Test metallic ion charge.
     magnesium_pdb = PDB()
     magnesium_atom = Atom(element="MG",
                           coordinates=Point(coords=np.array([0, 0, 0])))
     magnesium_pdb.add_new_non_protein_atom(magnesium_atom)
     metallic_charges = magnesium_pdb.identify_metallic_charges()
     assert len(metallic_charges) == 1
    def test_connected_heavy_atoms(self):
        """
    TestPDB: Verifies retrieval of connected heavy atoms.
    """
        # Verify that no atoms are present when we start.
        assert len(self.pdb.all_atoms.keys()) == 0
        carbon_atom = Atom(element="C")
        oxygen_atom = Atom(element="O")
        hydrogen_atom = Atom(element="H")

        self.pdb.add_new_atom(carbon_atom)
        self.pdb.add_new_atom(oxygen_atom)
        self.pdb.add_new_atom(hydrogen_atom)

        # We want a carboxyl, so C connects O and H
        carbon_atom.indices_of_atoms_connecting = [2, 3]
        oxygen_atom.indices_of_atoms_connecting = [1]
        hydrogen_atom.indices_of_atoms_connecting = [1]

        connected_heavy_atoms = self.pdb.connected_heavy_atoms(1)
        assert len(connected_heavy_atoms) == 1
        assert connected_heavy_atoms[0] == 2
예제 #9
0
  def test_connected_heavy_atoms(self):
    """
    TestPDB: Verifies retrieval of connected heavy atoms.
    """
    # Verify that no atoms are present when we start.
    assert len(self.pdb.all_atoms.keys()) == 0
    carbon_atom = Atom(element="C")
    oxygen_atom = Atom(element="O")
    hydrogen_atom = Atom(element="H")

    self.pdb.add_new_atom(carbon_atom)
    self.pdb.add_new_atom(oxygen_atom)
    self.pdb.add_new_atom(hydrogen_atom)

    # We want a carboxyl, so C connects O and H
    carbon_atom.indices_of_atoms_connecting = [2, 3]
    oxygen_atom.indices_of_atoms_connecting = [1]
    hydrogen_atom.indices_of_atoms_connecting = [1]

    connected_heavy_atoms = self.pdb.connected_heavy_atoms(1)
    assert len(connected_heavy_atoms) == 1
    assert connected_heavy_atoms[0] == 2