示例#1
0
def distance(f):
    ai = Selection("resid 50").evaluate(f)
    bi = Selection("resid 60").evaluate(f)
    min_dist = float("inf")
    for i in ai:
        for j in bi:
            d = f.distance(i, j)
            if d < min_dist:
                min_dist = d
示例#2
0
def distance(frame):
    # FIXME: this should use Selection("resid 50 and [chainname] A") which will
    # be available in chemfiles 0.10 (the next release)
    r50 = Selection("resid 50 and index < 1000").evaluate(frame)
    r60 = Selection("resid 60 and index < 1000").evaluate(frame)

    min = float('inf')
    for i in r50:
        for j in r60:
            r = frame.distance(i, j)
            if r < min:
                min = r

    return min
示例#3
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
示例#4
0
def count(frame):
    selection = Selection("resname ALA")
    return len(selection.evaluate(frame))
示例#5
0
import numpy as np
import math

from chemfiles import Trajectory, UnitCell, Atom, Topology, Frame, Selection
name = 'nt12-24-full.trj_wrap'  #name of the trajectory wrapped around the nanotube axis
a = 24  #the a box length

# 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)
示例#6
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)
示例#7
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)
示例#8
0
 def test_string(self):
     self.assertEqual(Selection("name H").string, "name H")
示例#9
0
 def test_size(self):
     self.assertEqual(Selection("name H").size, 1)
     self.assertEqual(Selection("pairs: all").size, 2)
     self.assertEqual(Selection("dihedrals: all").size, 4)
示例#10
0
 def test_copy(self):
     # Just checking that we can call copy.copy on a selction
     selection = Selection("name H")
     copy.copy(selection)
示例#11
0
 def test_repr(self):
     self.assertEqual(Selection("name H").__repr__(), "Selection('name H')")
示例#12
0
def count(f):
    len(Selection("resname ALA and name CA").evaluate(f))
示例#13
0
import numpy as np
import math

from chemfiles import Trajectory, UnitCell, Atom, Topology, Frame, Selection
name='nt12-24-full.trj_wrap'  #name of the trajectory wrapped around the nanotube axis
a=24 #the a box length

# 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)
示例#14
0
frame = Trajectory(name + ".xyz").read()

# 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)
示例#15
0
frame = Trajectory(name+".xyz").read()

# 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)
示例#16
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()