コード例 #1
0
ファイル: files_in.py プロジェクト: pmetzger/nanoengineer
def insertin(assy, filename):
    _init()

    dir, nodename = os.path.split(filename)

    mol = Chunk(assy, nodename)
    mol.showOverlayText = True

    file = open(filename)
    lines = file.readlines()
    atoms = {}
    transform = InternalCoordinatesToCartesian(len(lines), None)
    for line in lines:
        columns = line.strip().split()
        index = int(columns[0])
        name = columns[1]
        type = columns[2]
        na = int(columns[4])
        nb = int(columns[5])
        nc = int(columns[6])
        r = float(columns[7])
        theta = float(columns[8])
        phi = float(columns[9])

        transform.addInternal(index, na, nb, nc, r, theta, phi)
        xyz = transform.getCartesian(index)

        if (index > 3):
            if (AMBER_AtomTypes.has_key(type)):
                sym = AMBER_AtomTypes[type]
            else:
                print "unknown AMBER atom type, substituting Carbon: %s" % type
                sym = "C"

            a = Atom(sym, A(xyz), mol)
            atoms[index] = a
            a.setOverlayText(type)
            if (na > 3):
                a2 = atoms[na]
                bond_atoms(a, a2)

    assy.addmol(mol)
コード例 #2
0
def insertin(assy, filename):
    _init()

    dir, nodename = os.path.split(filename)

    mol = Chunk(assy, nodename)
    mol.showOverlayText = True

    file = open(filename)
    lines = file.readlines()
    atoms = {}
    transform = InternalCoordinatesToCartesian(len(lines), None)
    for line in lines:
        columns = line.strip().split()
        index = int(columns[0])
        name = columns[1]
        type = columns[2]
        na = int(columns[4])
        nb = int(columns[5])
        nc = int(columns[6])
        r = float(columns[7])
        theta = float(columns[8])
        phi = float(columns[9])

        transform.addInternal(index, na, nb, nc, r, theta, phi)
        xyz = transform.getCartesian(index)

        if (index > 3):
            if (AMBER_AtomTypes.has_key(type)):
                sym = AMBER_AtomTypes[type]
            else:
                print "unknown AMBER atom type, substituting Carbon: %s" % type
                sym = "C"

            a = Atom(sym, A(xyz), mol)
            atoms[index] = a
            a.setOverlayText(type)
            if (na > 3):
                a2 = atoms[na]
                bond_atoms(a, a2)

    assy.addmol(mol)
コード例 #3
0
    def _buildResidue(self, mol, zmatrix, n_atoms, idx, phi, psi, secondary, init_pos, residue_name, fake_chain=False):
        """
        Builds cartesian coordinates for an amino acid from the internal
        coordinates table.

        @param mol: a chunk to which the amino acid will be added.
        @type mol: Chunk

        @param zmatrix: is an internal coordinates array corresponding to a
        given amino acid.
        @type zmatrix: list

        @param n_atoms: size of z-matrix (a number of atoms to be build + 3
        dummy atoms)
        @type n_atoms: int

        @param idx: is a residue index (1..length).
        @type idx: integer

        @param phi, psi: peptide bond phi and psi angles
        @type phi, psi: float

        @param init_pos: optional postions of previous CA, C and O atoms.
        @type init_pos: V

        @param symbol: current amino acid symbol (used to derermine proline case)
        @type symbol: string

        """

        # note: currently, it doesn't rebuild bonds, so inferBonds has to be
        # called after this method. Unfortunately, the proper bond order can
        # not be correctly recognized this way. Therefore, temporary atom flags
        # _is_aromatic and _is_single are used.

        #this code was re-factored by EricM and internal-to-cartesian
        # conversion method was moved to geometry.InternalCoordinatesToCartesian

        if mol is None:
            return

        if not init_pos: # assign three previous atom positions
            coords = self.prev_coords
        else:
            # if no prev_coords are given, compute the first three atom positions
            coords = zeros([3,3], Float)
            num, name, atom_name, atom_type, \
               atom_c, atom_b, atom_a, r, a, t = zmatrix[1]
            coords[0][0] = 0.0;
            coords[0][1] = 0.0;
            coords[0][2] = 0.0;
            coords[1][0] = r;
            coords[1][1] = 0.0;
            coords[1][2] = 0.0;
            ccos = cos(DEG2RAD*a)
            num, name, atom_name, atom_type, \
               atom_c, atom_b, atom_a, r, a, t = zmatrix[2]
            if atom_c == 1:
                coords[2][0] = coords[0][0] + r*ccos
            else:
                coords[2][0] = coords[0][0] - r*ccos
            coords[2][1] = r * sin(DEG2RAD*a)
            coords[2][2] = 0.0
            for i in range (0, 3):
                self.prev_coords[i][0] = coords[i][0] + init_pos[0]
                self.prev_coords[i][1] = coords[i][1] + init_pos[1]
                self.prev_coords[i][2] = coords[i][2] + init_pos[2]

        translator = InternalCoordinatesToCartesian(n_atoms, coords)

        for n in range (3, n_atoms):
            # Generate all coordinates using three previous atoms
            # as a frame of reference,
            num, name, atom_name, atom_type, \
               atom_c, atom_b, atom_a, r, a, t = zmatrix[n]

            # Apply the peptide bond conformation
            if residue_name != "PRO":
                if name == "N  " and not init_pos:
                    t = self.prev_psi + 0.0
                if name == "O  ":
                    t = psi + 180.0
                if name == "HA " or name == "HA2":
                    t = 120.0 + phi
                if name == "CB " or name == "HA3":
                    t = 240.0 + phi
                if name == "C  ":
                    t = phi
            else:
                # proline
                if name == "N  " and not init_pos:
                    t = self.prev_psi + 0.0
                if name == "O  ":
                    t = psi + 180.0
                if name == "CA ":
                    t = phi - 120.0
                if name == "CD ":
                    t = phi + 60.0

            translator.addInternal(n+1, atom_c+1, atom_b+1, atom_a+1, r, a, t)
            xyz = translator.getCartesian(n+1)

            if self.nterm_hydrogen:
                # This is a hack for the first hydrogen atom
                # to make sure the bond length is correct.
                self.nterm_hydrogen.setposn(
                    self.nterm_hydrogen.posn() + \
                    0.325 * norm(xyz))
                self.nterm_hydrogen = None

            # Store previous coordinates for the next building step
            if not init_pos:
                if name=="N  ":
                    self.prev_coords[0][0] = xyz[0]
                    self.prev_coords[0][1] = xyz[1]
                    self.prev_coords[0][2] = xyz[2]
                if name=="CA ":
                    self.prev_coords[1][0] = xyz[0]
                    self.prev_coords[1][1] = xyz[1]
                    self.prev_coords[1][2] = xyz[2]
                if name=="C  ":
                    self.prev_coords[2][0] = xyz[0]
                    self.prev_coords[2][1] = xyz[1]
                    self.prev_coords[2][2] = xyz[2]

            # Add a new atom to the molecule
            if not fake_chain or \
               name == "CA ":
                atom = Atom(
                    atom_name,
                    xyz,
                    mol)

                if not self.init_ca and \
                   name == "CA ":
                    self.init_ca = atom

                if mol.protein:
                    aa = mol.protein.add_pdb_atom(atom,
                                             name.replace(' ',''),
                                             idx,
                                             AA_3_TO_1[residue_name])
                    atom.pdb_info = {}
                    atom.pdb_info['atom_name'] = name.replace(' ','')
                    atom.pdb_info['residue_name'] = residue_name
                    residue_id = "%3d " % idx
                    atom.pdb_info['residue_id'] = residue_id
                    atom.pdb_info['standard_atom'] = True
                    atom.pdb_info['chain_id'] = True
                    if aa:
                        aa.set_secondary_structure(secondary)

                # Create temporary attributes for proper bond assignment.
                atom._is_aromatic = False
                atom._is_single = False

                if atom_type == "sp2a":
                    atom_type = "sp2"
                    atom._is_aromatic = True

                if atom_type == "sp2s":
                    atom_type = "sp2"
                    atom._is_single = True

                atom.set_atomtype_but_dont_revise_singlets(atom_type)

                ### debug - output in PDB format
                ### print "ATOM  %5d  %-3s %3s %c%4d    %8.3f%8.3f%8.3f" % ( n, name, "ALA", ' ', res_num, xyz[0], xyz[1], xyz[2])

        self.prev_psi = psi # Remember previous psi angle.

        return
コード例 #4
0
    def _buildResidue(self,
                      mol,
                      zmatrix,
                      n_atoms,
                      idx,
                      phi,
                      psi,
                      secondary,
                      init_pos,
                      residue_name,
                      fake_chain=False):
        """
        Builds cartesian coordinates for an amino acid from the internal
        coordinates table.

        @param mol: a chunk to which the amino acid will be added.
        @type mol: Chunk

        @param zmatrix: is an internal coordinates array corresponding to a
        given amino acid.
        @type zmatrix: list

        @param n_atoms: size of z-matrix (a number of atoms to be build + 3
        dummy atoms)
        @type n_atoms: int

        @param idx: is a residue index (1..length).
        @type idx: integer

        @param phi, psi: peptide bond phi and psi angles
        @type phi, psi: float

        @param init_pos: optional postions of previous CA, C and O atoms.
        @type init_pos: V

        @param symbol: current amino acid symbol (used to derermine proline case)
        @type symbol: string

        """

        # note: currently, it doesn't rebuild bonds, so inferBonds has to be
        # called after this method. Unfortunately, the proper bond order can
        # not be correctly recognized this way. Therefore, temporary atom flags
        # _is_aromatic and _is_single are used.

        #this code was re-factored by EricM and internal-to-cartesian
        # conversion method was moved to geometry.InternalCoordinatesToCartesian

        if mol is None:
            return

        if not init_pos:  # assign three previous atom positions
            coords = self.prev_coords
        else:
            # if no prev_coords are given, compute the first three atom positions
            coords = zeros([3, 3], Float)
            num, name, atom_name, atom_type, \
               atom_c, atom_b, atom_a, r, a, t = zmatrix[1]
            coords[0][0] = 0.0
            coords[0][1] = 0.0
            coords[0][2] = 0.0
            coords[1][0] = r
            coords[1][1] = 0.0
            coords[1][2] = 0.0
            ccos = cos(DEG2RAD * a)
            num, name, atom_name, atom_type, \
               atom_c, atom_b, atom_a, r, a, t = zmatrix[2]
            if atom_c == 1:
                coords[2][0] = coords[0][0] + r * ccos
            else:
                coords[2][0] = coords[0][0] - r * ccos
            coords[2][1] = r * sin(DEG2RAD * a)
            coords[2][2] = 0.0
            for i in range(0, 3):
                self.prev_coords[i][0] = coords[i][0] + init_pos[0]
                self.prev_coords[i][1] = coords[i][1] + init_pos[1]
                self.prev_coords[i][2] = coords[i][2] + init_pos[2]

        translator = InternalCoordinatesToCartesian(n_atoms, coords)

        for n in range(3, n_atoms):
            # Generate all coordinates using three previous atoms
            # as a frame of reference,
            num, name, atom_name, atom_type, \
               atom_c, atom_b, atom_a, r, a, t = zmatrix[n]

            # Apply the peptide bond conformation
            if residue_name != "PRO":
                if name == "N  " and not init_pos:
                    t = self.prev_psi + 0.0
                if name == "O  ":
                    t = psi + 180.0
                if name == "HA " or name == "HA2":
                    t = 120.0 + phi
                if name == "CB " or name == "HA3":
                    t = 240.0 + phi
                if name == "C  ":
                    t = phi
            else:
                # proline
                if name == "N  " and not init_pos:
                    t = self.prev_psi + 0.0
                if name == "O  ":
                    t = psi + 180.0
                if name == "CA ":
                    t = phi - 120.0
                if name == "CD ":
                    t = phi + 60.0

            translator.addInternal(n + 1, atom_c + 1, atom_b + 1, atom_a + 1,
                                   r, a, t)
            xyz = translator.getCartesian(n + 1)

            if self.nterm_hydrogen:
                # This is a hack for the first hydrogen atom
                # to make sure the bond length is correct.
                self.nterm_hydrogen.setposn(
                    self.nterm_hydrogen.posn() + \
                    0.325 * norm(xyz))
                self.nterm_hydrogen = None

            # Store previous coordinates for the next building step
            if not init_pos:
                if name == "N  ":
                    self.prev_coords[0][0] = xyz[0]
                    self.prev_coords[0][1] = xyz[1]
                    self.prev_coords[0][2] = xyz[2]
                if name == "CA ":
                    self.prev_coords[1][0] = xyz[0]
                    self.prev_coords[1][1] = xyz[1]
                    self.prev_coords[1][2] = xyz[2]
                if name == "C  ":
                    self.prev_coords[2][0] = xyz[0]
                    self.prev_coords[2][1] = xyz[1]
                    self.prev_coords[2][2] = xyz[2]

            # Add a new atom to the molecule
            if not fake_chain or \
               name == "CA ":
                atom = Atom(atom_name, xyz, mol)

                if not self.init_ca and \
                   name == "CA ":
                    self.init_ca = atom

                if mol.protein:
                    aa = mol.protein.add_pdb_atom(atom, name.replace(' ', ''),
                                                  idx, AA_3_TO_1[residue_name])
                    atom.pdb_info = {}
                    atom.pdb_info['atom_name'] = name.replace(' ', '')
                    atom.pdb_info['residue_name'] = residue_name
                    residue_id = "%3d " % idx
                    atom.pdb_info['residue_id'] = residue_id
                    atom.pdb_info['standard_atom'] = True
                    atom.pdb_info['chain_id'] = True
                    if aa:
                        aa.set_secondary_structure(secondary)

                # Create temporary attributes for proper bond assignment.
                atom._is_aromatic = False
                atom._is_single = False

                if atom_type == "sp2a":
                    atom_type = "sp2"
                    atom._is_aromatic = True

                if atom_type == "sp2s":
                    atom_type = "sp2"
                    atom._is_single = True

                atom.set_atomtype_but_dont_revise_singlets(atom_type)

                ### debug - output in PDB format
                ### print "ATOM  %5d  %-3s %3s %c%4d    %8.3f%8.3f%8.3f" % ( n, name, "ALA", ' ', res_num, xyz[0], xyz[1], xyz[2])

        self.prev_psi = psi  # Remember previous psi angle.

        return