Exemplo n.º 1
0
    def __call__(self, f):
        Universe = context.application.plugins.get_node("Universe")
        universe = Universe()
        Folder = context.application.plugins.get_node("Folder")
        folder = Folder()

        Atom = context.application.plugins.get_node("Atom")
        counter = 1
        atom_index = 0
        for line in f:
            #if len(line) != 81:
            #    raise FilterError("Each line in a PDB file must count 80 characters, error at line %i, len=%i" % (counter, len(line)-1))
            if line.startswith("ATOM"):
                extra = {"index": atom_index}
                atom_info = periodic[line[76:78].strip()]
                try:
                    t = numpy.array([
                        float(line[30:38].strip()),
                        float(line[38:46].strip()),
                        float(line[46:54].strip())
                    ]) * angstrom
                except ValueError:
                    raise FilterError(
                        "Error while reading PDB file: could not read coordinates at line %i."
                        % counter)
                atom = Atom(name=line[12:16].strip(),
                            number=atom_info.number,
                            transformation=Translation(t),
                            extra=extra)
                universe.add(atom)
                atom_index += 1
            elif line.startswith("CRYST1"):
                space_group = line[55:66].strip().upper()
                if space_group != "P 1":
                    raise FilterError(
                        "Error while reading PDB file: only unit cells with space group P 1 are supported."
                    )
                a = float(line[6:15].strip()) * angstrom
                b = float(line[15:24].strip()) * angstrom
                c = float(line[24:33].strip()) * angstrom
                alpha = float(line[33:40].strip()) * numpy.pi / 180
                beta = float(line[40:47].strip()) * numpy.pi / 180
                gamma = float(line[47:54].strip()) * numpy.pi / 180
                universe.set_cell(
                    UnitCell.from_parameters3([a, b, c], [alpha, beta, gamma]))
            counter += 1

        return [universe, folder]
Exemplo n.º 2
0
    def __call__(self, f):
        Universe = context.application.plugins.get_node("Universe")
        universe = Universe()
        Folder = context.application.plugins.get_node("Folder")
        folder = Folder()

        Atom = context.application.plugins.get_node("Atom")
        counter = 1
        atom_index =  0
        for line in f:
            #if len(line) != 81:
            #    raise FilterError("Each line in a PDB file must count 80 characters, error at line %i, len=%i" % (counter, len(line)-1))
            if line.startswith("ATOM"):
                extra = {"index": atom_index}
                atom_info = periodic[line[76:78].strip()]
                try:
                    t = numpy.array([
                            float(line[30:38].strip()),
                            float(line[38:46].strip()),
                            float(line[46:54].strip())
                    ]) * angstrom
                except ValueError:
                    raise FilterError("Error while reading PDB file: could not read coordinates at line %i." % counter)
                atom = Atom(
                    name=line[12:16].strip(), number=atom_info.number,
                    transformation=Translation(t), extra=extra
                )
                universe.add(atom)
                atom_index += 1
            elif line.startswith("CRYST1"):
                space_group = line[55:66].strip().upper()
                if space_group != "P 1":
                    raise FilterError("Error while reading PDB file: only unit cells with space group P 1 are supported.")
                a = float(line[6:15].strip())*angstrom
                b = float(line[15:24].strip())*angstrom
                c = float(line[24:33].strip())*angstrom
                alpha = float(line[33:40].strip())*numpy.pi/180
                beta = float(line[40:47].strip())*numpy.pi/180
                gamma = float(line[47:54].strip())*numpy.pi/180
                universe.set_cell(UnitCell.from_parameters3([a, b, c], [alpha, beta, gamma]))
            counter += 1

        return [universe, folder]
Exemplo n.º 3
0
 def convert_to_value(self, representation):
     lengths, angles = ComposedInTable.convert_to_value(
         self, representation)
     return UnitCell.from_parameters3(lengths, angles)
Exemplo n.º 4
0
 def convert_to_value(self, representation):
     lengths, angles = ComposedInTable.convert_to_value(self, representation)
     return UnitCell.from_parameters3(lengths, angles)