from modeller import *

log.verbose()
env = Environ()

# Read in the sequence database in binary format
sdb = SequenceDB(env, seq_database_file='pdb_95.hdf5',
                 seq_database_format='BINARY', chains_list='ALL')

# Read in the target sequence in PIR alignment format
aln = Alignment(env)
aln.append(file='TvLDH.ali', alignment_format='PIR', align_codes='ALL')

# Convert the input sequence "alignment" into profile format
prf = aln.to_profile()

# Scan sequence database to pick up homologous sequences
prf.build(sdb, matrix_offset=-450, rr_file='${LIB}/blosum62.sim.mat',
          gap_penalties_1d=(-500, -50), n_prof_iterations=1,
          check_profile=False, max_aln_evalue=0.01)

# Write out the profile in text format
prf.write(file='build_profile.prf', profile_format='TEXT')

# Convert the profile back to alignment format
aln = prf.to_alignment()

#- Write out a PIR alignment file
aln.write(file='build_profile.ali', alignment_format='PIR')
