Example #1
0
def ramachandran(frame):
    phi_selection = Selection(
        "dihedrals: name(#1) C and name(#2) N and name(#3) CA and name(#4) C")
    phi_angles = []
    for (i, j, k, m) in phi_selection.evaluate(frame):
        # 57.29578 to convert from radians to degrees
        phi_angles.append(frame.dihedral(i, j, k, m) * 57.29578)

    psi_selection = Selection(
        "dihedrals: name(#1) N and name(#2) CA and name(#3) C and name(#4) N")
    psi_angles = []
    for (i, j, k, m) in psi_selection.evaluate(frame):
        psi_angles.append(frame.dihedral(i, j, k, m) * 57.29578)

    # FIXME: the sign of the angles is inverted w.r.t. the MDAnalysis results
    return phi_angles, psi_angles
Example #2
0
    def test_evaluate(self):
        frame = testing_frame()

        selection = Selection("name H")
        res = selection.evaluate(frame)
        self.assertEqual(res, [0, 3])

        selection = Selection("bonds: all")
        res = selection.evaluate(frame)

        self.assertIn((0, 1), res)
        self.assertIn((1, 2), res)
        self.assertIn((2, 3), res)

        selection = Selection("angles: all")
        res = selection.evaluate(frame)

        self.assertIn((0, 1, 2), res)
        self.assertIn((1, 2, 3), res)

        selection = Selection("dihedrals: all")
        res = selection.evaluate(frame)

        self.assertEqual([(0, 1, 2, 3)], res)
Example #3
0
def count(frame):
    selection = Selection("resname ALA")
    return len(selection.evaluate(frame))
Example #4
0
# Read the traj
trajectory = Trajectory(name + '.xyz')

# Set the topology
topo = Trajectory("topology.pdb").read()
trajectory.set_topology(topo.topology())

# Select all
selection = Selection("all")

Ral = 6.5

with Trajectory(name + '_flat.xyz', 'w') as output:
    for frame in trajectory:
        nt = selection.evaluate(frame)
        positions = frame.positions()

        for atom in nt:
            x = positions[atom][0]
            y = positions[atom][1]

            r = math.sqrt(x * x + y * y)
            theta = math.atan2(y, x)

            positions[atom, 0] = theta * Ral
            positions[atom, 1] = Ral - r

        output.write(frame)

trajectory.close()
Example #5
0
# This file is an example for the chemfiles library
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
#!/usr/bin/env python
from chemfiles import Trajectory, Selection

trajectory = Trajectory("input.arc")
output = Trajectory("output.pdb", 'w')

selection = Selection("name Zn or name N")

for frame in trajectory:
    to_remove = selection.evaluate(frame)
    for i in reversed(sorted(to_remove)):
        frame.remove(i)
    output.write(frame)
Example #6
0
# Read the traj
trajectory = Trajectory(name+'.xyz')

# Set the topology
topo = Trajectory("topology.pdb").read()
trajectory.set_topology(topo.topology())

# Select all
selection = Selection("all")

Ral=6.5

with Trajectory(name+'_flat.xyz','w') as output:
    for frame in trajectory:
        nt = selection.evaluate(frame)
        positions = frame.positions()

        for atom in nt:
            x=positions[atom][0]
            y=positions[atom][1]

            r=math.sqrt(x*x+y*y)
            theta=math.atan2(y,x)

            positions[atom,0]=theta*Ral
	    positions[atom,1]=Ral-r
  
        output.write(frame)

trajectory.close()
Example #7
0
# Set the topology
topo = Trajectory("topology.pdb").read()
frame.set_topology(topo.topology())

# Get the positions
positions = frame.positions()

# Set the cell
cell = UnitCell(a, a, 42.43, 90, 90, 120)
frame.set_cell(cell)

# Select all except hydroxyl groups
#selection = Selection("atoms: name Al or name Obr or name Si")
selection = Selection(
    "atoms: name Hext or name Oext or name Al or name Obr or name Si")
framework = selection.evaluate(frame)

with open(name + ".cris", 'w') as cris:
    with open(name + ".slice.xyz", 'w') as slic:
        with open(name + ".framework.xyz", 'w') as out:
            cris.write(" .false.\n")
            cris.write('{} {} 8.486 90.0 90.0 120.0\n'.format(a, a))
            cris.write('{}\n'.format(len(framework) / 5))

            slic.write('{}\n\n'.format(len(framework) / 5))
            out.write('{}\n\n'.format(len(framework)))
            for (ind, i) in enumerate(framework):
                atom = frame.atom(i)
                if atom.name() == "Al":
                    atom.set_charge(1.5750)
                    num = 1
Example #8
0
# Set the topology
topo = Trajectory("topology.pdb").read()
frame.set_topology(topo.topology())

# Get the positions
positions = frame.positions()

# Set the cell
cell = UnitCell(a, a, 42.43, 90, 90, 120)
frame.set_cell(cell)

# Select all except hydroxyl groups
#selection = Selection("atoms: name Al or name Obr or name Si")
selection = Selection("atoms: name Hext or name Oext or name Al or name Obr or name Si")
framework = selection.evaluate(frame)

with open(name+".cris",'w') as cris:
    with open(name+".slice.xyz",'w') as slic:
        with open(name+".framework.xyz",'w') as out:
            cris.write(" .false.\n")
            cris.write('{} {} 8.486 90.0 90.0 120.0\n'.format(a, a))
            cris.write('{}\n'.format(len(framework)/5))
 
            slic.write('{}\n\n'.format(len(framework)/5))
            out.write('{}\n\n'.format(len(framework)))
            for (ind,i) in enumerate(framework):
                atom = frame.atom(i)
                if atom.name() == "Al":
                    atom.set_charge(1.5750)
                    num = 1
Example #9
0
# This file is an example for the chemfiles library
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
#!/usr/bin/env python
from chemfiles import Trajectory, Selection

trajectory = Trajectory("input.arc")
output = Trajectory("output.pdb", 'w')

selection = Selection("name Zn or name N")

for frame in trajectory:
    to_remove = selection.evaluate(frame)
    for i in reversed(sorted(to_remove)):
        frame.remove(i)
    output.write(frame)

trajectory.close()
output.close()