Beispiel #1
0
    def calculate_BSA(self):
        "Uses NACCESS module in order to calculate the Buried Surface Area"

        # Extract list of chains in the interface only
        chains = list(self.get_chains())
           
        # Create temporary structures to feed NACCESS
        structure_A=Structure("chainA")
        structure_B=Structure("chainB")
        mA = Model(0)
        mB = Model(0)
        mA.add(self.model[chains[0]])
        mB.add(self.model[chains[1]])
        structure_A.add(mA)
        structure_B.add(mB)
        
        # Calculate SASAs
        NACCESS_atomic(self.model)
        NACCESS_atomic(structure_A[0])
        NACCESS_atomic(structure_B[0])

        sas_tot= _get_atomic_SASA(self.model)
        #print 'Accessible surface area, complex:', sas_tot
        sas_A= _get_atomic_SASA(structure_A)
        #print 'Accessible surface aream CHAIN A :', sas_A
        sas_B= _get_atomic_SASA(structure_B)
        #print 'Accessible surface aream CHAIN B :',sas_B
        
        # Calculate BSA
        bsa = sas_A+sas_B-sas_tot
                
        return [bsa, sas_A, sas_B, sas_tot]
Beispiel #2
0
    def _rsa_calculation(self, model, chain_list, rsa_threshold):
        "Uses NACCESS module in order to calculate the Buried Surface Area"
        pairs=[]
        # Create temporary structures to feed NACCESS
        structure_A=Structure("chainA")
        structure_B=Structure("chainB")
        mA = Model(0)
        mB = Model(0)
        mA.add(model[chain_list[0]])
        mB.add(model[chain_list[1]])
        structure_A.add(mA)
        structure_B.add(mB)
        # Calculate SASAs
        nacc_at=NACCESS(model)
        model_values=[]
                
        res_list = [r for r in model.get_residues() if r.id[0] == ' ']
        structure_A_reslist =[r for r in structure_A[0].get_residues() if r.id[0] == ' ']
        structure_B_reslist =[r for r in structure_B[0].get_residues() if r.id[0] == ' ']
        
        for res in res_list:
            model_values.append(float(res.xtra['EXP_NACCESS']['all_atoms_rel']))
            
                
        sas_tot= self._get_residue_SASA(model)
        #print 'Accessible surface area, complex:', sas_tot

        nacc_at=NACCESS(structure_A[0])
        nacc_at=NACCESS(structure_B[0])
        submodel_values=[]
                
        for res in structure_A_reslist:
            if res.id[0]==' ':
                submodel_values.append(float(res.xtra['EXP_NACCESS']['all_atoms_rel']))                
                
        for res in structure_B_reslist:
            if res.id[0]==' ':
                submodel_values.append(float(res.xtra['EXP_NACCESS']['all_atoms_rel']))
        
        count=0        
        for res in res_list:
            if res in structure_A_reslist and ((submodel_values[count] - model_values[count]) > rsa_threshold):
                pairs.append(res)
            elif res in structure_B_reslist and ((submodel_values[count] - model_values[count]) > rsa_threshold):
                pairs.append(res)
            count=count+1
        
        
        sas_A= self._get_residue_SASA(structure_A)
        #print 'Accessible surface aream CHAIN A :', sas_A
        sas_B= self._get_residue_SASA(structure_B)
        #print 'Accessible surface aream CHAIN B :',sas_B
        
        # Calculate BSA
        bsa = sas_A+sas_B-sas_tot
                
        self.interface.accessibility=[bsa, sas_A, sas_B, sas_tot]
        
        return pairs
Beispiel #3
0
    def __create_superimposed_pdb(self):
        def fill_in_chain(chain, protein_id, rotation_matrix = None):
            for index,residue in enumerate(self.proteins[protein_id].get_residues()):
                residue.id = (residue.id[0], index, residue.id[2])
                chain.add(residue)

        merged_model = Model(0)
        chain_a = Chain('A')
        chain_b = Chain('B')

        fill_in_chain(chain_a, 0)
        fill_in_chain(chain_b, 1)

        merged_model.add(chain_a)
        merged_model.add(chain_b)

        return merged_model
class StructureBuilder(object):
    """
    Deals with contructing the Structure object. The StructureBuilder class is used
    by the PDBParser classes to translate a file to a Structure object.
    """
    def __init__(self):
        self.line_counter=0
        self.header={}

    def _is_completely_disordered(self, residue):
        "Return 1 if all atoms in the residue have a non blank altloc."
        atom_list=residue.get_unpacked_list()
        for atom in atom_list:
            altloc=atom.get_altloc()
            if altloc==" ":
                return 0
        return 1

    # Public methods called by the Parser classes

    def set_header(self, header):
        self.header=header

    def set_line_counter(self, line_counter):
        """
        The line counter keeps track of the line in the PDB file that
        is being parsed.

        Arguments:
        o line_counter - int
        """
        self.line_counter=line_counter

    def init_structure(self, structure_id):
        """Initiate a new Structure object with given id.

        Arguments:
        o id - string
        """
        self.structure=Structure(structure_id)

    def init_model(self, model_id, serial_num = None):
        """Initiate a new Model object with given id.

        Arguments:
        o id - int
        o serial_num - int
        """
        self.model=Model(model_id,serial_num)
        self.structure.add(self.model)

    def init_chain(self, chain_id):
        """Initiate a new Chain object with given id.

        Arguments:
        o chain_id - string
        """
        if self.model.has_id(chain_id):
            self.chain=self.model[chain_id]
            warnings.warn("WARNING: Chain %s is discontinuous at line %i."
                          % (chain_id, self.line_counter),
                          PDBConstructionWarning)
        else:
            self.chain=Chain(chain_id)
            self.model.add(self.chain)

    def init_seg(self, segid):
        """Flag a change in segid.

        Arguments:
        o segid - string
        """
        self.segid=segid

    def init_residue(self, resname, field, resseq, icode):
        """
        Initiate a new Residue object.

        Arguments:
        o resname - string, e.g. "ASN"
        o field - hetero flag, "W" for waters, "H" for
            hetero residues, otherwise blank.
        o resseq - int, sequence identifier
        o icode - string, insertion code
        """
        if field!=" ":
            if field=="H":
                # The hetero field consists of H_ + the residue name (e.g. H_FUC)
                field="H_"+resname
        res_id=(field, resseq, icode)
        if field==" ":
            if self.chain.has_id(res_id):
                # There already is a residue with the id (field, resseq, icode).
                # This only makes sense in the case of a point mutation.
                warnings.warn("WARNING: Residue ('%s', %i, '%s') "
                              "redefined at line %i."
                              % (field, resseq, icode, self.line_counter),
                              PDBConstructionWarning)
                duplicate_residue=self.chain[res_id]
                if duplicate_residue.is_disordered()==2:
                    # The residue in the chain is a DisorderedResidue object.
                    # So just add the last Residue object.
                    if duplicate_residue.disordered_has_id(resname):
                        # The residue was already made
                        self.residue=duplicate_residue
                        duplicate_residue.disordered_select(resname)
                    else:
                        # Make a new residue and add it to the already
                        # present DisorderedResidue
                        new_residue=Residue(res_id, resname, self.segid)
                        duplicate_residue.disordered_add(new_residue)
                        self.residue=duplicate_residue
                        return
                else:
                    # Make a new DisorderedResidue object and put all
                    # the Residue objects with the id (field, resseq, icode) in it.
                    # These residues each should have non-blank altlocs for all their atoms.
                    # If not, the PDB file probably contains an error.
                    if not self._is_completely_disordered(duplicate_residue):
                        # if this exception is ignored, a residue will be missing
                        self.residue=None
                        raise PDBConstructionException(
                            "Blank altlocs in duplicate residue %s ('%s', %i, '%s')"
                            % (resname, field, resseq, icode))
                    self.chain.detach_child(res_id)
                    new_residue=Residue(res_id, resname, self.segid)
                    disordered_residue=DisorderedResidue(res_id)
                    self.chain.add(disordered_residue)
                    disordered_residue.disordered_add(duplicate_residue)
                    disordered_residue.disordered_add(new_residue)
                    self.residue=disordered_residue
                    return
        residue=Residue(res_id, resname, self.segid)
        self.chain.add(residue)
        self.residue=residue

    def init_atom(self, name, coord, b_factor, occupancy, altloc, fullname,
                  serial_number=None, element=None):
        """
        Initiate a new Atom object.

        Arguments:
        o name - string, atom name, e.g. CA, spaces should be stripped
        o coord - Numeric array (Float0, size 3), atomic coordinates
        o b_factor - float, B factor
        o occupancy - float
        o altloc - string, alternative location specifier
        o fullname - string, atom name including spaces, e.g. " CA "
        o element - string, upper case, e.g. "HG" for mercury
        """
        residue=self.residue
        # if residue is None, an exception was generated during
        # the construction of the residue
        if residue is None:
            return
        # First check if this atom is already present in the residue.
        # If it is, it might be due to the fact that the two atoms have atom
        # names that differ only in spaces (e.g. "CA.." and ".CA.",
        # where the dots are spaces). If that is so, use all spaces
        # in the atom name of the current atom.
        if residue.has_id(name):
                duplicate_atom=residue[name]
                # atom name with spaces of duplicate atom
                duplicate_fullname=duplicate_atom.get_fullname()
                if duplicate_fullname!=fullname:
                    # name of current atom now includes spaces
                    name=fullname
                    warnings.warn("Atom names %r and %r differ "
                                  "only in spaces at line %i."
                                  % (duplicate_fullname, fullname,
                                     self.line_counter),
                                  PDBConstructionWarning)
        atom=self.atom=Atom(name, coord, b_factor, occupancy, altloc,
                            fullname, serial_number, element)
        if altloc!=" ":
            # The atom is disordered
            if residue.has_id(name):
                # Residue already contains this atom
                duplicate_atom=residue[name]
                if duplicate_atom.is_disordered()==2:
                    duplicate_atom.disordered_add(atom)
                else:
                    # This is an error in the PDB file:
                    # a disordered atom is found with a blank altloc
                    # Detach the duplicate atom, and put it in a
                    # DisorderedAtom object together with the current
                    # atom.
                    residue.detach_child(name)
                    disordered_atom=DisorderedAtom(name)
                    residue.add(disordered_atom)
                    disordered_atom.disordered_add(atom)
                    disordered_atom.disordered_add(duplicate_atom)
                    residue.flag_disordered()
                    warnings.warn("WARNING: disordered atom found "
                                  "with blank altloc before line %i.\n"
                                  % self.line_counter,
                                  PDBConstructionWarning)
            else:
                # The residue does not contain this disordered atom
                # so we create a new one.
                disordered_atom=DisorderedAtom(name)
                residue.add(disordered_atom)
                # Add the real atom to the disordered atom, and the
                # disordered atom to the residue
                disordered_atom.disordered_add(atom)
                residue.flag_disordered()
        else:
            # The atom is not disordered
            residue.add(atom)

    def set_anisou(self, anisou_array):
        "Set anisotropic B factor of current Atom."
        self.atom.set_anisou(anisou_array)

    def set_siguij(self, siguij_array):
        "Set standard deviation of anisotropic B factor of current Atom."
        self.atom.set_siguij(siguij_array)

    def set_sigatm(self, sigatm_array):
        "Set standard deviation of atom position of current Atom."
        self.atom.set_sigatm(sigatm_array)

    def get_structure(self):
        "Return the structure."
        # first sort everything
        # self.structure.sort()
        # Add the header dict
        self.structure.header=self.header
        return self.structure

    def set_symmetry(self, spacegroup, cell):
        pass
Beispiel #5
0
model = Model(1)
chain = Chain("A")
structure = Structure("ref")

num_count = 0
for i in range(0,shape(points)[0]):
    num_count = num_count +1
    res_id = (' ',num_count,' ')
    residue = Residue(res_id,'ALA',' ')
    cur_coord = tuple(points[i])
    bfactor = bfactors[i]
    atom = Atom('CA',cur_coord,bfactor,0,' ','CA',num_count,'C')
    residue.add(atom)
    chain.add(residue)

model.add(chain)
structure.add(model)
# --------------------------------------------------------------------
io=PDBIO()
io.set_structure(structure)
if ( args['dst'] is None):
    fn = sys.stdout
    io.save(fn)
    if ( args['link'] ):
        for i in range(1,shape(points)[0]):
            fn.write( "CONECT%5d%5d\n" % (i, i+1))
else:
    fn = args['dst']
    io.save(fn)
    fout = open(fn,"a")
    if (args['link'] ):
Beispiel #6
0
refid = "ref"
structure = Structure(refid)
model_ref = Model(1)
chain_ref = Chain("A")
points_ref = ReadXYZ(ref_ptsfilename,scale)
	
num_count = 0
for i in range(0,shape(points_ref[IndexList])[0]):
	num_count = num_count +1
	res_id = (' ',num_count,' ')
	residue = Residue(res_id,'ALA',' ')
	cur_coord = tuple(points_ref[IndexList[i]])
	atom = Atom('CA',cur_coord,0,0,' ',num_count,num_count,'C')
	residue.add(atom)
	chain_ref.add(residue)
model_ref.add(chain_ref)
structure.add(model_ref)

#--------------------------------------------------------------------
altid = "alt"
structure_alt = Structure(refid)
model_alt = Model(2)
chain_alt = Chain("A")
points_alt = ReadXYZ(alt_ptsfilename,scale)
	
num_count = 0
for i in range(0,shape(points_alt[IndexList])[0]):
	num_count = num_count +1
	res_id = (' ',num_count,' ')
	residue = Residue(res_id,'ALA',' ')
	cur_coord = tuple(points_alt[IndexList[i]])
Beispiel #7
0
class StructureBuilder(object):
    """
    Deals with contructing the Structure object. The StructureBuilder class is used
    by the PDBParser classes to translate a file to a Structure object.
    """
    def __init__(self):
        self.line_counter = 0
        self.header = {}

    def _is_completely_disordered(self, residue):
        "Return 1 if all atoms in the residue have a non blank altloc."
        atom_list = residue.get_unpacked_list()
        for atom in atom_list:
            altloc = atom.get_altloc()
            if altloc == " ":
                return 0
        return 1

    # Public methods called by the Parser classes

    def set_header(self, header):
        self.header = header

    def set_line_counter(self, line_counter):
        """
        The line counter keeps track of the line in the PDB file that
        is being parsed.

        Arguments:
        o line_counter - int
        """
        self.line_counter = line_counter

    def init_structure(self, structure_id):
        """Initiate a new Structure object with given id.

        Arguments:
        o id - string
        """
        self.structure = Structure(structure_id)

    def init_model(self, model_id, serial_num=None):
        """Initiate a new Model object with given id.

        Arguments:
        o id - int
        o serial_num - int
        """
        self.model = Model(model_id, serial_num)
        self.structure.add(self.model)

    def init_chain(self, chain_id):
        """Initiate a new Chain object with given id.

        Arguments:
        o chain_id - string
        """
        if self.model.has_id(chain_id):
            self.chain = self.model[chain_id]
            warnings.warn(
                "WARNING: Chain %s is discontinuous at line %i." %
                (chain_id, self.line_counter), PDBConstructionWarning)
        else:
            self.chain = Chain(chain_id)
            self.model.add(self.chain)

    def init_seg(self, segid):
        """Flag a change in segid.

        Arguments:
        o segid - string
        """
        self.segid = segid

    def init_residue(self, resname, field, resseq, icode):
        """
        Initiate a new Residue object.

        Arguments:
        o resname - string, e.g. "ASN"
        o field - hetero flag, "W" for waters, "H" for
            hetero residues, otherwise blank.
        o resseq - int, sequence identifier
        o icode - string, insertion code
        """
        if field != " ":
            if field == "H":
                # The hetero field consists of H_ + the residue name (e.g. H_FUC)
                field = "H_" + resname
        res_id = (field, resseq, icode)
        if field == " ":
            if self.chain.has_id(res_id):
                # There already is a residue with the id (field, resseq, icode).
                # This only makes sense in the case of a point mutation.
                warnings.warn(
                    "WARNING: Residue ('%s', %i, '%s') "
                    "redefined at line %i." %
                    (field, resseq, icode, self.line_counter),
                    PDBConstructionWarning)
                duplicate_residue = self.chain[res_id]
                if duplicate_residue.is_disordered() == 2:
                    # The residue in the chain is a DisorderedResidue object.
                    # So just add the last Residue object.
                    if duplicate_residue.disordered_has_id(resname):
                        # The residue was already made
                        self.residue = duplicate_residue
                        duplicate_residue.disordered_select(resname)
                    else:
                        # Make a new residue and add it to the already
                        # present DisorderedResidue
                        new_residue = Residue(res_id, resname, self.segid)
                        duplicate_residue.disordered_add(new_residue)
                        self.residue = duplicate_residue
                        return
                else:
                    # Make a new DisorderedResidue object and put all
                    # the Residue objects with the id (field, resseq, icode) in it.
                    # These residues each should have non-blank altlocs for all their atoms.
                    # If not, the PDB file probably contains an error.
                    if not self._is_completely_disordered(duplicate_residue):
                        # if this exception is ignored, a residue will be missing
                        self.residue = None
                        raise PDBConstructionException(
                            "Blank altlocs in duplicate residue %s ('%s', %i, '%s')"
                            % (resname, field, resseq, icode))
                    self.chain.detach_child(res_id)
                    new_residue = Residue(res_id, resname, self.segid)
                    disordered_residue = DisorderedResidue(res_id)
                    self.chain.add(disordered_residue)
                    disordered_residue.disordered_add(duplicate_residue)
                    disordered_residue.disordered_add(new_residue)
                    self.residue = disordered_residue
                    return
        residue = Residue(res_id, resname, self.segid)
        self.chain.add(residue)
        self.residue = residue

    def init_atom(self,
                  name,
                  coord,
                  b_factor,
                  occupancy,
                  altloc,
                  fullname,
                  serial_number=None,
                  element=None):
        """
        Initiate a new Atom object.

        Arguments:
        o name - string, atom name, e.g. CA, spaces should be stripped
        o coord - Numeric array (Float0, size 3), atomic coordinates
        o b_factor - float, B factor
        o occupancy - float
        o altloc - string, alternative location specifier
        o fullname - string, atom name including spaces, e.g. " CA "
        o element - string, upper case, e.g. "HG" for mercury
        """
        residue = self.residue
        # if residue is None, an exception was generated during
        # the construction of the residue
        if residue is None:
            return
        # First check if this atom is already present in the residue.
        # If it is, it might be due to the fact that the two atoms have atom
        # names that differ only in spaces (e.g. "CA.." and ".CA.",
        # where the dots are spaces). If that is so, use all spaces
        # in the atom name of the current atom.
        if residue.has_id(name):
            duplicate_atom = residue[name]
            # atom name with spaces of duplicate atom
            duplicate_fullname = duplicate_atom.get_fullname()
            if duplicate_fullname != fullname:
                # name of current atom now includes spaces
                name = fullname
                warnings.warn(
                    "Atom names %r and %r differ "
                    "only in spaces at line %i." %
                    (duplicate_fullname, fullname, self.line_counter),
                    PDBConstructionWarning)
        atom = self.atom = Atom(name, coord, b_factor, occupancy, altloc,
                                fullname, serial_number, element)
        if altloc != " ":
            # The atom is disordered
            if residue.has_id(name):
                # Residue already contains this atom
                duplicate_atom = residue[name]
                if duplicate_atom.is_disordered() == 2:
                    duplicate_atom.disordered_add(atom)
                else:
                    # This is an error in the PDB file:
                    # a disordered atom is found with a blank altloc
                    # Detach the duplicate atom, and put it in a
                    # DisorderedAtom object together with the current
                    # atom.
                    residue.detach_child(name)
                    disordered_atom = DisorderedAtom(name)
                    residue.add(disordered_atom)
                    disordered_atom.disordered_add(atom)
                    disordered_atom.disordered_add(duplicate_atom)
                    residue.flag_disordered()
                    warnings.warn(
                        "WARNING: disordered atom found "
                        "with blank altloc before line %i.\n" %
                        self.line_counter, PDBConstructionWarning)
            else:
                # The residue does not contain this disordered atom
                # so we create a new one.
                disordered_atom = DisorderedAtom(name)
                residue.add(disordered_atom)
                # Add the real atom to the disordered atom, and the
                # disordered atom to the residue
                disordered_atom.disordered_add(atom)
                residue.flag_disordered()
        else:
            # The atom is not disordered
            residue.add(atom)

    def set_anisou(self, anisou_array):
        "Set anisotropic B factor of current Atom."
        self.atom.set_anisou(anisou_array)

    def set_siguij(self, siguij_array):
        "Set standard deviation of anisotropic B factor of current Atom."
        self.atom.set_siguij(siguij_array)

    def set_sigatm(self, sigatm_array):
        "Set standard deviation of atom position of current Atom."
        self.atom.set_sigatm(sigatm_array)

    def get_structure(self):
        "Return the structure."
        # first sort everything
        # self.structure.sort()
        # Add the header dict
        self.structure.header = self.header
        return self.structure

    def set_symmetry(self, spacegroup, cell):
        pass
Beispiel #8
0
		# num_count = num_count + 1
		# res_id = (' ',num_count,' ')
		# residue = Residue(res_id,'ALA',' ')
		# cur_coord = start_point_1
		# atom = Atom('CA',cur_coord,0,1,' ',num_count,num_count,'C')
		# residue.add(atom)
		# chain.add(residue)
		# 
		# num_count = num_count + 1
		# res_id = (' ',num_count,' ')
		# residue = Residue(res_id,'ALA',' ')
		# cur_coord = start_point_2
		# atom = Atom('CA',cur_coord,0,1,' ',num_count,num_count,'C')
		# residue.add(atom)
		# chain.add(residue)
	model.add(chain[j])
		
structure.add(model)
# --------------------------------------------------------------------

# for model in structure:
#	print
	# for chain in model: 
	# 	for residue in chain:
	# 		for atom in residue:
#				print atom.get_full_id()
#				print atom.coord


io=PDBIO()
io.set_structure(structure)
Beispiel #9
0
}, {
    'name': 'C5',
    'coord': PDB.Atom.array([66.402, 44.364, 11.291], 'f'),
    'bfactor': 44.20,
    'occupancy': 1.0,
    'altloc': ' ',
    'fullname': 'C5',
    'serial_number': 7
}, {
    'name': 'C6',
    'coord': PDB.Atom.array([65.095, 44.589, 11.192], 'f'),
    'bfactor': 44.33,
    'occupancy': 1.0,
    'altloc': ' ',
    'fullname': 'C6',
    'serial_number': 8
}]
my_structure.add(my_model)
my_model.add(my_chain)
my_chain.add(my_residue)

for atom in atoms:
    my_atom = Atom(atom['name'], atom['coord'], atom['bfactor'],
                   atom['occupancy'], atom['altloc'], atom['fullname'],
                   atom['serial_number'])
    my_residue.add(my_atom)

out = PDBIO()
out.set_structure(my_structure)
out.save('my_new_structure.pdb')
Beispiel #10
0
def normalize_structure(input_path: str,
                        pdb_id: str,
                        model_id: int,
                        chain_id: str,
                        primary: str,
                        mask: str,
                        save=True,
                        verbose=True):
    assert primary
    assert mask
    with warnings.catch_warnings(record=True):
        warnings.simplefilter("ignore", PDBConstructionWarning)
        parser = PDBParser()
        structure = parser.get_structure(pdb_id, input_path)
        if not model_id in structure.child_dict:
            try_model_id = model_id - 1
            model = None
            while try_model_id >= 0:
                if try_model_id in structure.child_dict:
                    model = structure.child_dict[try_model_id]
                    if verbose:
                        print('Supposing model {} is {}...'.format(
                            model_id - 1, model_id))
                try_model_id -= 1
            if not model:
                raise ValueError(
                    'model "{}" not found in "{}", options are {}'.format(
                        model_id, pdb_id, list(structure.child_dict.keys())))
        else:
            model = structure.child_dict[model_id]
        if not chain_id in model.child_dict:
            raise ValueError(
                'chain "{}" not found in "{}" model "{}", options are {}'.
                format(chain_id, pdb_id, model_id,
                       list(model.child_dict.keys())))
        chain = model.child_dict[chain_id]

        new_chain = normalize_chain(chain)

        raw = []
        for residue in chain:
            try:
                raw.append(resname_to_abbrev(residue.resname))
            except UnknownResnameError:
                # if verbose:
                #    print('Skipping residue "{}"'.format(residue.resname))
                pass
        raw = ''.join(raw)

        # verify that the sequence is what we expect
        normalized = []
        for residue in new_chain:
            try:
                normalized.append(resname_to_abbrev(residue.resname))
            except UnknownResnameError:
                # if verbose:
                #    print('Skipping residue "{}"'.format(residue.resname))
                pass
        normalized = ''.join(normalized)

        # extract the known primary sequence using the mask
        masked_primary = []
        for r, m in zip(primary, mask):
            if m == '-':
                continue
            assert m == '+'
            masked_primary.append(r)
        masked_primary = ''.join(masked_primary)

        # ensure the sequence lengths match
        if len(normalized) != len(masked_primary):
            raise ChainLengthError(len(normalized), len(masked_primary))

        # ensure residue identities match
        for i, (got, expected) in enumerate(zip(normalized, masked_primary)):
            if got != expected:
                raise ValueError(
                    'mismatch residue at position {} (got {}, expected {})'.
                    format(i, got, expected))

        new_model = Model(model.id)
        new_model.add(new_chain)
        new_structure = Structure(structure.id)
        new_structure.add(new_model)

        if save:
            out_path = input_path + '.norm'
            io = PDBIO()
            io.set_structure(new_structure)
            io.save(out_path)
            return out_path
        else:
            return new_structure
Beispiel #11
0
model_ref = Model(1)
chain_ref = Chain("A")
points_ref = ReadXYZ(ref_ptsfilename,scale)
	
num_count = 0
for i in range(0,shape(points_ref[IndexList])[0]):
	num_count = num_count +1
	# res_id = (' ',IndexList[i],' ')
	res_id = (' ',num_count,' ')	
	residue = Residue(res_id,'ALA',' ')
	cur_coord = tuple(points_ref[IndexList[i]])
	# atom = Atom('CA',cur_coord,0,0,' ',num_count,num_count,'C')
	atom = Atom('CA',cur_coord,0,0,' ',num_count,num_count,'C')
	residue.add(atom)
	chain_ref.add(residue)
model_ref.add(chain_ref)
structure.add(model_ref)

#--------------------------------------------------------------------
print ("scale=%s" % scale)

#--------------------------------------------------------------------
io=PDBIO()
io.set_structure(structure)
fn = outputfilename
io.save(fn)
fout = open(fn,"a")
for i in range(1,shape(points_ref[IndexList])[0]):
	fout.write( "CONECT%5d%5d\n" % (i, i+1))
print "output file: " + outputfilename
def initialize_res(residue):
    '''Creates a new structure containing a single amino acid. The type and
    geometry of the amino acid are determined by the argument, which has to be
    either a geometry object or a single-letter amino acid code.
    The amino acid will be placed into chain A of model 0.'''
    
    if isinstance( residue, Geo ):
        geo = residue
    else:
        geo=geometry(residue) 
    
    segID=1
    AA= geo.residue_name
    CA_N_length=geo.CA_N_length
    CA_C_length=geo.CA_C_length
    N_CA_C_angle=geo.N_CA_C_angle
    
    CA_coord= numpy.array([0.,0.,0.])
    C_coord= numpy.array([CA_C_length,0,0])
    N_coord = numpy.array([CA_N_length*math.cos(N_CA_C_angle*(math.pi/180.0)),CA_N_length*math.sin(N_CA_C_angle*(math.pi/180.0)),0])

    N= Atom("N", N_coord, 0.0 , 1.0, " "," N", 0, "N")
    CA=Atom("CA", CA_coord, 0.0 , 1.0, " "," CA", 0,"C")
    C= Atom("C", C_coord, 0.0, 1.0, " ", " C",0,"C")

    ##Create Carbonyl atom (to be moved later)
    C_O_length=geo.C_O_length
    CA_C_O_angle=geo.CA_C_O_angle
    N_CA_C_O_diangle=geo.N_CA_C_O_diangle
    
    carbonyl=calculateCoordinates(N, CA, C, C_O_length, CA_C_O_angle, N_CA_C_O_diangle)
    O= Atom("O",carbonyl , 0.0 , 1.0, " "," O", 0, "O")

    if(AA=='G'):
        res=makeGly(segID, N, CA, C, O, geo)
    elif(AA=='A'):
        res=makeAla(segID, N, CA, C, O, geo)
    elif(AA=='S'):
        res=makeSer(segID, N, CA, C, O, geo)
    elif(AA=='C'):
        res=makeCys(segID, N, CA, C, O, geo)
    elif(AA=='V'):
        res=makeVal(segID, N, CA, C, O, geo)
    elif(AA=='I'):
        res=makeIle(segID, N, CA, C, O, geo)
    elif(AA=='L'):
        res=makeLeu(segID, N, CA, C, O, geo)
    elif(AA=='T'):
        res=makeThr(segID, N, CA, C, O, geo)
    elif(AA=='R'):
        res=makeArg(segID, N, CA, C, O, geo)
    elif(AA=='K'):
        res=makeLys(segID, N, CA, C, O, geo)
    elif(AA=='D'):
        res=makeAsp(segID, N, CA, C, O, geo)
    elif(AA=='E'):
        res=makeGlu(segID, N, CA, C, O, geo)
    elif(AA=='N'):
        res=makeAsn(segID, N, CA, C, O, geo)
    elif(AA=='Q'):
        res=makeGln(segID, N, CA, C, O, geo)
    elif(AA=='M'):
        res=makeMet(segID, N, CA, C, O, geo)
    elif(AA=='H'):
        res=makeHis(segID, N, CA, C, O, geo)
    elif(AA=='P'):
        res=makePro(segID, N, CA, C, O, geo)
    elif(AA=='F'):
        res=makePhe(segID, N, CA, C, O, geo)
    elif(AA=='Y'):
        res=makeTyr(segID, N, CA, C, O, geo)
    elif(AA=='W'):
        res=makeTrp(segID, N, CA, C, O, geo)
    else:
        res=makeGly(segID, N, CA, C, O, geo)

    cha= Chain('A')
    cha.add(res)
    
    mod= Model(0)
    mod.add(cha)

    struc= Structure('X')
    struc.add(mod)
    return struc