コード例 #1
0
ファイル: test_relaxin.py プロジェクト: penglian518/psfgen
def test_delete():
    """
    Tests removing atoms
    """
    from psfgen import PsfGen
    os.chdir(dir)

    gen = PsfGen(output=os.devnull)
    gen.read_topology("top_all36_caps.rtf")
    gen.read_topology("top_all36_prot.rtf")

    gen.add_segment(segid="P0", pdbfile="psf_protein_P0.pdb")
    gen.read_coords(segid="P0", filename="psf_protein_P0.pdb")

    # Delete a specific atom
    assert "CAY" in gen.get_atom_names(segid="P0", resid=1)
    gen.delete_atoms(segid="P0", resid=1, atomname="CAY")
    assert "CAY" not in gen.get_atom_names(segid="P0", resid=1)

    # Try deleting a capping group
    assert gen.get_resids("P0") == [str(_) for _ in range(1, 26)]
    gen.delete_atoms(segid="P0", resid=1)
    assert gen.get_resids("P0") == [str(_) for _ in range(2, 26)]

    # Add and then delete a segment
    gen.add_segment(segid="DELETE", pdbfile="psf_protein_P1.pdb")
    assert gen.get_segids() == ["P0", "DELETE"]
    gen.delete_atoms(segid="DELETE")
    assert gen.get_segids() == ["P0"]
コード例 #2
0
ファイル: test_relaxin.py プロジェクト: penglian518/psfgen
def test_set():
    """
    Tests that setters work correctly
    """
    from psfgen import PsfGen
    os.chdir(dir)

    gen = PsfGen(output=os.devnull)
    gen.read_topology("top_all36_caps.rtf")
    gen.read_topology("top_all36_prot.rtf")

    gen.add_segment(segid="P", pdbfile="psf_protein_P1.pdb")
    assert gen.get_segids() == ["P"]

    # Set segid
    gen.set_segid(segid="P", new_segid="P1")
    assert gen.get_segids() == ["P1"]

    gen.read_coords(segid="P1", filename="psf_protein_P1.pdb")

    # Set resname
    assert gen.get_resname(segid="P1", resid="1") == "ASP"
    gen.set_resname(segid="P1", resid="1", new_resname="ASH")
    assert gen.get_resname(segid="P1", resid="1") == "ASH"

    # Set charge
    gen.set_charge(segid="P1", resid="1", atomname="O", charge=-1.)
    assert -1.0 in gen.get_charges(segid="P1", resid="1")

    # Set atom name
    gen.set_atom_name(segid="P1", resid="1", atomname="N", new_atomname="NO")
    assert "N" not in gen.get_atom_names(segid="P1", resid="1")
    assert "NO" in gen.get_atom_names(segid="P1", resid="1")

    # Set coord
    gen.set_position(segid="P1",
                     resid="1",
                     atomname="HN",
                     position=(0., 0., -1.))
    assert (0., 0., -1.) in gen.get_coordinates(segid="P1", resid="1")

    # Set velocity
    gen.set_velocity(segid="P1",
                     resid="1",
                     atomname="NO",
                     velocity=(
                         5.,
                         5.,
                         3.,
                     ))
    assert (
        5.,
        5.,
        3.,
    ) in gen.get_velocities(segid="P1", resid="1")
コード例 #3
0
ファイル: test_relaxin.py プロジェクト: penglian518/psfgen
def test_alias():
    """
    Tests atom and residue aliases, either at the topology or the PDB level
    """
    from psfgen import PsfGen
    os.chdir(dir)

    gen = PsfGen(output=os.devnull)
    gen.read_topology("top_all36_caps.rtf")
    gen.read_topology("top_all36_prot.rtf")

    gen.alias_residue(top_resname="LEU", pdb_resname="LEX")
    gen.alias_residue(top_resname="ARG", pdb_resname="AAA")
    gen.alias_atom(top_atomname="N", pdb_atomname="NOOO", resname="PHE")

    gen.add_segment(segid="P", pdbfile="protein_newnames.pdb")
    gen.read_coords(segid="P", filename="psf_protein_P0.pdb")

    assert gen.get_resname(segid="P", resid=2) == "LEU"
    assert gen.get_resname(segid="P", resid=5) == "ALA"
    assert "N" in gen.get_atom_names(segid="P", resid=23)
コード例 #4
0
ファイル: test_relaxin.py プロジェクト: penglian518/psfgen
def test_query():
    """
    Tests that query functions work correctly
    """

    from psfgen import PsfGen
    gen = PsfGen(output=os.devnull)
    os.chdir(dir)

    gen.read_topology("top_all36_caps.rtf")
    gen.read_topology("top_all36_prot.rtf")

    gen.add_segment(segid="P0", pdbfile="psf_protein_P0.pdb")
    gen.read_coords(segid="P0", filename="psf_protein_P0.pdb")

    gen.add_segment(segid="P1", pdbfile="psf_protein_P1.pdb")
    gen.read_coords(segid="P1", filename="psf_protein_P1.pdb")

    gen.patch(patchname="DISU", targets=[("P0", "10"), ("P0", "15")])

    assert gen.get_topologies() == ["top_all36_caps.rtf", "top_all36_prot.rtf"]

    # Check residue names query
    resnames = gen.get_residue_types()
    assert len(resnames) == 26
    assert "CYS" in resnames
    assert "TIP3" not in resnames

    # Check patches query
    patches = gen.get_patches(list_all=True)
    assert len(patches) == 25
    assert "CYSD" in patches
    assert "SEP" not in patches

    # Check segids query
    assert gen.get_segids() == ["P0", "P1"]

    # Check resids query
    assert gen.get_resids("P0") == [str(_) for _ in range(1, 26)]
    assert gen.get_resids("P1") == [str(_) for _ in range(0, 31)]

    # Check resname query, with str or int
    assert gen.get_resname(segid="P0", resid="2") == "LEU"
    assert gen.get_resname(segid="P1", resid=29) == "SER"

    # Check applied patches query
    assert gen.get_patches() == [("DISU", "P0", "10"), ("DISU", "P0", "15")]
    assert gen.get_first(segid="P0") is None
    assert gen.get_last(segid="P1") is None

    # Check atom queries
    assert gen.get_atom_names(segid="P0", resid="10") \
                == ['N', 'HN', 'CA', 'HA', 'CB', 'HB1', 'HB2', 'SG', 'C', 'O']
    assert set(gen.get_masses(segid="P0", resid=1)) == {1.008, 12.011, 15.999}
    assert gen.get_atom_indices(segid="P1", resid=0) == list(range(1, 7))
    assert set(gen.get_charges(segid="P0", resid="10")) \
        == {-0.47, 0.07, 0.09, 0.31, -0.1, -0.08, 0.51, -0.51}

    # Check coordinates and velocities
    assert len(gen.get_coordinates(segid="P1", resid=25)) == 17
    assert set(gen.get_velocities(segid="P1", resid=1)) == {(0., 0., 0.)}