def __init__(self, log): self.log = log self.log_class_heading = log_file_heading+"Class: "\ +self.__class__.__name__ log_method_heading = self.log_class_heading+" Method: "+stack()[0][3]\ +" ::: " self.log.write_log("log", log_method_heading + "Initialization called") self.struct = sct.Structure(self.log)
def writeFiles(fileBase,AL,FF,exceptResidues=[]): fixAtomNames(AL) ST = structure.Structure(AL,FF,exceptResidues=exceptResidues) ut = Cont() # keep track of the USED TYPES so that we can make a par file afterwards ut.atomtypes = ST.usedAtomLabels writePsf(fileBase+'.psf',AL,FF,ST,ut) writePrm(fileBase+'.prm',FF,ut) pdb.writeFile(fileBase+'.pdb',AL,withConect=False)
def __init__(self, name): self.name = name self.reviews = [] self.graph = GRAPH.opinionGraph() self.matrix = [] self.leaders = [] self.communities = [] self.outliers = [] self.structure = STRUCT.Structure()
def post(self): # pylint:disable=g-bad-name """Deal with request to queue up a new operation.""" user = users.get_current_user() job_data = json.loads(self.request.body) # clean up request data if 'replication' not in job_data: job_data['replication'] = 1 job_data['replication'] = int( job_data['replication'] ) if job_data['replication'] > REPLICATION_LIMIT: job_data['replication'] = REPLICATION_LIMIT elif job_data['replication'] < 1: job_data['replication'] = 1 pdb_hash = hashlib.sha1(str(job_data['pdbdata'])).hexdigest() # set up a new operation data block and set some reasonable initial values new_operation = Operation( parent=Operation.Key(operation_list_name)) new_operation.user_id = user.user_id() new_operation.structure_key = '' new_operation.structure_hash = pdb_hash new_operation.replication = job_data['replication'] new_operation.parentkey = job_data['parent_operation'] new_operation.job_data = json.dumps(job_data) new_operation.info = json.dumps(job_data['operation_info'], separators=(',', ':')) new_operation.count_results = 0 new_operation.count_errors = 0 new_operation.count_cputime = 0 new_operation.last_stderr = '' new_operation.put() # Also create a data entry for the structure itself newstructure = structure.Structure( parent=structure.Structure.Key(structure.structure_list_name)) newstructure.user_id = user.user_id() newstructure.workerinfo = '' newstructure.pdbdata = str(job_data['pdbdata']) newstructure.hash_sha1 = pdb_hash newstructure.operation = str(new_operation.key()) newstructure.put() new_operation.structure_key = str(newstructure.key()) new_operation.put() taskdata = { 'key': str(newstructure.key()), 'hash_sha1': newstructure.hash_sha1, 'user_id': user.user_id(), 'operation': newstructure.operation, 'job_data': json.dumps(job_data) } task.QueueTasks(taskdata, job_data['replication']) self.response.set_status(200)
def configure_location(session, event): '''Listen.''' for location_name, disk_prefix in zip(LOCATION_NAMES, DISK_PREFIXES): location = session.ensure('Location', {'name': location_name}) location.accessor = ftrack_api.accessor.disk.DiskAccessor( prefix=disk_prefix) location.structure = structure.Structure() location.priority = 1 logger.info(u'Registered location {0} at {1}.'.format( location_name, disk_prefix))
def __init__(self, r_struct=None): self.beads, self.score, self.mtype, self.basepairs = [], 0, motif_type.UNKNOWN, [] self.path, self.name, self.ends = "", "", [] self.end_ids = [] self.structure = structure.Structure() self.secondary_structure = secondary_structure.Motif() self.block_end_add = 0 self.id = uuid.uuid1() self.protein_beads = [] if r_struct is not None: self.__dict__.update(r_struct.__dict__) self.secondary_structure = ssf.factory.secondary_structure_from_motif(self)
def split_pose_by_chains(self, p): ps = [] for c in p.chains(): p_new = pose.Pose() s = structure.Structure([c.copy()]) p.structure = s bps = [] for bp in p.basepairs: pass ps.append(p) return ps
def str_to_structure(s): """ creates an structure from string generated from :func:`rnamake.structure.Structure.to_str` :param s: string containing stringifed structure :type s: str :returns: unstringifed structure object :rtype: structure.Structure """ spl = s.split(":") struct = structure.Structure() chains = [] for c_str in spl[:-1]: c = str_to_chain(c_str) chains.append(c) struct.chains = chains return struct
def write_poscar(inp_str, outfile='POSCAR'): """Writes POSCAR file from Structure or VASP object""" out_str = [] assert isinstance(inp_str, structure.Structure) or isinstance(inp_str,Vasp), "'write_poscar' function input must be of type 'Structure' or 'Vasp'" # Look for VASP object first, since it is superclass if isinstance(inp_str, Vasp): out_str = copy.deepcopy(inp_str) elif isinstance(inp_str,structure.Structure): out_str = Vasp(comment='Default VASP POSCAR', scale='1.0', struct=structure.Structure(lattice=inp_str.lattice, coords=inp_str.coords, species=inp_str.species), iscartesian=True) dir = os.getcwd() filename = dir + '/' + outfile with open(filename, 'w') as f: f.write(out_str.comment + '\n') f.write(str(out_str.scale)+ '\n') for row in out_str.structure.lattice: f.write('{0:15} {1:15} {2:15}'.format(str(format(row[0], '.10f')), str(format(row[1], '.10f')), str(format(row[2], '.10f'))) + '\n') unique_elements = set(out_str.structure.species) f.write('\t'+ '\t'.join(unique_elements)+ '\n') el_num = [0] * len(unique_elements) for i, element in enumerate(unique_elements): el_num[i]=out_str.structure.species.count(element) f.write('\t'+ '\t'.join(str(x) for x in el_num) + '\n') if out_str.iscartesian: f.write("Cartesian" + '\n') for row in out_str.structure.coords: f.write('{0:>12} {1:>12} {2:>12}'.format(str(row[0]), str(row[1]), str(row[2])) + '\n') f.close()
def generateLammpsData(al, ff, fileBase, cell=None, debug=False, exceptResidues=[]): """denerates the data file with all the information for Lammps only rectangular cells are supported so cell is a list of tree values [xrange, yrange,zrange] with center 0,0,0 or 4x3 numpy array with the cell size in the NAMD notation """ filescript = fileBase + '.in' filedata = fileBase + '.data' if debug: print 'getting ready to write lammps input and datafiles: %s, %s' % ( filescript, filedata) st = structure.Structure(al, ff, debug=debug, exceptResidues=exceptResidues) # find out which angles and types are actually used # if the molecule is very flat bin style for neighbor crashes, so use nsq useNsqNeighbor = False xyz = atoms.getXyzFromList(al) xyzmax = numpy.max(xyz, axis=0) xyzmin = numpy.min(xyz, axis=0) xyzRange = xyzmax - xyzmin if min(xyzRange) < 2.5: useNsqNeighbor = True # periodicity considerations if cell == None: isPeriodic = False cellBoundary = 's s s' xyzmin = xyzmin - ff.cutoffNonBond xyzmax = xyzmax + ff.cutoffNonBond cell = [ xyzmin[0], xyzmax[0], xyzmin[1], xyzmax[1], xyzmin[2], xyzmax[2] ] else: isPeriodic = True cellBoundary = 'p p p' if len(cell) == 3: boxSize = numpy.zeros((4, 3)) boxSize[0, 0] = cell[0] boxSize[1, 1] = cell[1] boxSize[2, 2] = cell[2] elif len(cell) == 4: boxSize = cell else: sys.exit( 'Error: prepLammps in generateLammpsData: wrong input for cell dimensions (has to have length 3 or 4, but has %d' % len(cell)) # need to make sure all the atoms are in the main cell # make array with the box size in the NAMD notation periodic.putCoordinatesIntoBox(al, boxSize) # create list of 6 or 9 numbers xmin,xmax,xy... to specify lammps cell size # lammps: "origin" at (xlo,ylo,zlo) # 3 edge vectors starting from the origin given by # A = (xhi-xlo,0,0); # B = (xy,yhi-ylo,0); # C = (xz,yz,zhi-zlo). # check that the box has 0's in the right places: if boxSize[0, 1] != 0 or boxSize[0, 2] != 0 or boxSize[ 1, 2] != 0 or boxSize[0, 0] <= 0. or boxSize[ 1, 1] <= 0.0 or boxSize[2, 2] <= 0.: sys.exit( 'Error: prepLammps: cell vector A is not aligned with +x or B is not in xy plane: %s , but these are required by lammps' % str(boxSize)) # lammps has pretty weird definition of the periodic cell, just look at hte lammps online page to understand this... origin = boxSize[3, :] - (boxSize[0, :] + boxSize[1, :] + boxSize[2, :]) / 2 xlo = origin[0] ylo = origin[1] zlo = origin[2] lx = boxSize[0, 0] ly = boxSize[1, 1] lz = boxSize[2, 2] xy = boxSize[1, 0] xz = boxSize[2, 0] yz = boxSize[2, 1] xhi = xlo + lx yhi = ylo + ly zhi = zlo + lz cell = [xlo, xhi, ylo, yhi, zlo, zhi] if xy != 0 or xz != 0 or yz != 0: cell.append(xy) cell.append(xz) cell.append(yz) # variables describing pair styles: # # usedPairStyle -- vdw requested in the par file, morse or lj12-6 # isPeriodic # doHydrogenBonds # myHBondType - only defined if doHydrogenBonds is True # pairStyleHybrid # pairStyleVDW # pairStyleCoul - only defined if usedPairStyle == 'morse' # vdwtype usedPairStyle = ff.atomTypes[st.sortedAtomLabels[0]].vdwType # hbond type if len(st.sortedHydrogenBondTypes) > 0 and ff.doHbonds: doHydrogenBonds = True if st.sortedHydrogenBondTypes[0].type == 'morse': myHBondType = 'hbond/dreiding/morse' elif st.sortedHydrogenBondTypes[0].type == 'lj12-10': myHBondType = 'hbond/dreiding/lj' else: sys.exit('Erorr: unknown hydrogen bond type: %s' % (st.sortedHydrogenBondTypes[0].type)) else: doHydrogenBonds = False # is this hybrid pair style? if (not doHydrogenBonds) and usedPairStyle in ['lj12-6', 'exp6']: pairStyleHybrid = False else: pairStyleHybrid = True # prepare names if usedPairStyle == 'lj12-6': if isPeriodic: pairStyleVDW = 'lj/charmm/coul/long/opt' else: pairStyleVDW = 'lj/charmm/coul/charmm' elif usedPairStyle == 'exp6': if isPeriodic: pairStyleVDW = 'buck/coul/long' else: pairStyleVDW = 'buck/coul/cut' elif usedPairStyle == 'morse': pairStyleVDW = 'morse/opt' if isPeriodic: pairStyleCoul = 'coul/long' else: pairStyleCoul = 'coul/cut' else: sys.exit( 'Erorr: unknown VDW type in prepLammps.py (only lj12-6 and morse available now): %s' % usedPairStyle) # PREPROCESS EXPLICIT MIXING # hybrid pair does not mix so we need to check if we are doing hydrogen bonds pair_coeff_lines = [] if ( not pairStyleHybrid ) and usedPairStyle == 'lj12-6': # we only have to list offdiagonal VDW when it is requeted in the parameter file for i, index in enumerate(st.sortedAtomLabels): for j in range(i, len(st.sortedAtomLabels)): jindex = st.sortedAtomLabels[j] # first see, if we have to use off-diagonal rule, if not just compute it if index + jindex in ff.offDiagVDWTypes: params = ff.offDiagVDWTypes[index + jindex].lammps() pair_coeff_lines.append( 'pair_coeff %d %d %s # %s-%s\n' % (i + 1, j + 1, params, index, jindex)) elif jindex + index in ff.offDiagVDWTypes: params = ff.offDiagVDWTypes[jindex + index].lammps() pair_coeff_lines.append( 'pair_coeff %d %d %s # %s-%s\n' % (i + 1, j + 1, params, index, jindex)) else: # for hybrid pair style we have to list the offdiagonal VDW always if usedPairStyle == 'morse': # for morse coulomb is not included in the pair style but via hybrid pair_coeff_lines.append('pair_coeff * * %s\n' % pairStyleCoul) for i, index in enumerate(st.sortedAtomLabels): for j in range(i, len(st.sortedAtomLabels)): jindex = st.sortedAtomLabels[j] # first see, if we have to use off-diagonal rule, if not just compute it if index + jindex in ff.offDiagVDWTypes: params = ff.offDiagVDWTypes[index + jindex].lammps() elif jindex + index in ff.offDiagVDWTypes: params = ff.offDiagVDWTypes[jindex + index].lammps() else: # computing the diagonal rule here bi = ff.atomTypes[index] # these are atom bj = ff.atomTypes[jindex] params = bi.mixWith(bj, ff.mean).lammps() if pairStyleHybrid: pair_coeff_lines.append( 'pair_coeff %d %d %s %s # %s-%s\n' % (i + 1, j + 1, pairStyleVDW, params, index, jindex)) else: pair_coeff_lines.append( 'pair_coeff %d %d %s # %s-%s\n' % (i + 1, j + 1, params, index, jindex)) if doHydrogenBonds: myHBondPower = st.sortedHydrogenBondTypes[0].power for b in st.sortedHydrogenBondTypes: bd = st.usedAtomLabels[b.donor] + 1 bh = st.usedAtomLabels[b.hydrogen] + 1 ba = st.usedAtomLabels[b.acceptor] + 1 if bd <= ba: flag = 'i' bi = bd bj = ba else: flag = 'j' bi = ba bj = bd pair_coeff_lines.append( 'pair_coeff %d %d %s %d %s %s # donor:%s hydrogen:%s acceptor:%s \n' % (bi, bj, myHBondType, bh, flag, b.lammps(), b.donor, b.hydrogen, b.acceptor)) # OUTPUTTING # output the stuff if debug: print 'writing lammps input and datafile' # the script file with open(filescript, 'w') as script: script.write('boundary %s \n' % cellBoundary) script.write('units real \n') if useNsqNeighbor: script.write('neighbor 2.0 nsq\n') if ff.cutoffNonBond > 15.0: # the default number of neighbors in lammps is 2000 # the number of atoms in radius r is ~0.4*r^3, let's use 50% more estimate = int(0.6 * math.pow(ff.cutoffNonBond, 3.0)) bound = len(al) + 10 neighborone = max(2000, min(estimate, bound)) neighborpage = 20 * neighborone script.write('neigh_modify one %d page %d\n' % (neighborone, neighborpage)) pass #script.write('neigh_modify delay 10 every 1 check yes one 4000 page 40000\n') script.write(' \n') script.write('atom_style full \n') # BOND STYLE if len(st.usedBondTypes) > 0: script.write('bond_style harmonic\n') else: script.write('bond_style none \n') # ANGLE STYLE if len(st.usedAngleTypes) > 0: if st.sortedAngleTypes[0].type == 'harmonic': script.write('angle_style harmonic \n') else: # cosine angles as in dreiding script.write( 'angle_style hybrid cosine/periodic cosine/squared \n') else: script.write('angle_style none \n') # TORSION STYLE if len(st.usedTorsionTypes) > 0: script.write('dihedral_style harmonic \n') else: script.write('dihedral_style none \n') # INVERSION STYLE if len(st.usedInversionTypes) > 0: if st.sortedInversionTypes[0].type == 'amber': script.write('improper_style cvff \n') else: # dreiding inversion script.write('improper_style umbrella \n') else: script.write('improper_style none \n') script.write(' \n') # PAIR STYLE if not pairStyleHybrid: if usedPairStyle == 'lj12-6': script.write( 'pair_style %s %f %f \n' % (pairStyleVDW, ff.splineNonBond, ff.cutoffNonBond)) script.write( 'pair_modify mix %s \n' % ff.mean) # note that hte hybrid style does not do mixing elif usedPairStyle == 'exp6': script.write('pair_style %s %f \n' % (pairStyleVDW, ff.cutoffNonBond)) else: sys.exit( 'Error in prepLammps. One should never get to this part of code, but usedPairStyle is :%s' % usedPairStyle) else: pairStyleLine = 'pair_style hybrid/overlay' if usedPairStyle == 'lj12-6': pairStyleLine += ' %s %f %f' % (pairStyleVDW, ff.splineNonBond, ff.cutoffNonBond) elif usedPairStyle == 'morse': pairStyleLine += ' %s %f' % (pairStyleVDW, ff.cutoffNonBond) pairStyleLine += ' %s %f' % (pairStyleCoul, ff.cutoffNonBond) else: sys.exit( 'Erorr: unknown VDW type in prepLammps.py (only lj12-6 and morse available now): %s' % usedPairStyle) if doHydrogenBonds: pairStyleLine += ' %s %d %f %f %f \n' % ( myHBondType, myHBondPower, ff.splineHBond, ff.cutoffHBond, ff.angleHBond) pairStyleLine += ' \n' script.write(pairStyleLine) if isPeriodic: script.write('kspace_style pppm 1e-4 \n') script.write('dielectric %f \n' % ff.dielectric) if ff.special14lj == 1.0 and ff.special14coul == 1.0: script.write('special_bonds dreiding \n') elif ff.special14lj == 0.5 and ff.special14coul == 1.0 / 1.2: script.write('special_bonds amber \n') else: print >> sys.stderr, 'special14lj %f and special14coul %f is neither dreiding nor amber ' % ( ff.special14lj, ff.special14coul) sys.exit(1) script.write(' \n') script.write('read_data %s \n' % filedata) script.write(' \n') script.write( '#### alternatively read coordinates from the latest (*) restart file \n' ) script.write('# read_restart restart.*\n') script.write(' \n') for line in pair_coeff_lines: script.write(line) # write the run information into the script file # define computes script.write(' \n') script.write('variable step equal step \n') script.write('variable ebond equal ebond \n') script.write('variable eangle equal eangle \n') script.write('variable edihed equal edihed \n') script.write('variable eimp equal eimp \n') script.write('variable emol equal emol \n') script.write('variable ecoul equal ecoul \n') # the values reported by hbond computes are not correct, so have to use some global variables # try 1 after update #if doHydrogenBonds: # script.write('compute hbond all pair hbond/dreiding/%s \n' % myHBondType) # script.write('variable hbond equal c_hbond[2] \n') # script.write('variable counthbond equal c_hbond[1] \n') #else: # script.write('variable hbond equal 0.0 \n') # script.write('variable counthbond equal 0.0 \n') #script.write('variable evdwl equal evdwl-v_hbond \n') # NOTE: thermo evdwl already contains hbond # try 2 script.write('compute evdwl all pair %s evdwl \n' % pairStyleVDW) script.write('variable evdwl equal c_evdwl \n' ) # NOTE: thermo evdwl already contains hbond if doHydrogenBonds: script.write('compute hbondevdwl all pair %s evdwl \n' % myHBondType) script.write('variable hbond equal c_hbondevdwl \n') script.write('compute hbond all pair %s \n' % myHBondType) script.write('variable counthbond equal c_hbond[1] \n') else: script.write('variable hbond equal 0.0 \n') script.write('variable counthbond equal 0.0 \n') script.write('variable elong equal elong \n') script.write('variable epair equal epair \n') script.write('variable pe equal pe \n') script.write('variable ke equal ke \n') script.write('variable etotal equal etotal \n') script.write('variable temp equal temp \n') script.write('variable press equal press \n') script.write('variable fmax equal fmax \n') script.write(' \n') script.write('thermo 100 \n') script.write( 'thermo_style custom step ebond eangle edihed eimp emol ecoul v_evdwl v_hbond v_counthbond elong epair pe ke etotal temp press fmax\n' ) script.write(' \n') # fixed atoms # there is 2048 characters per line limit in lammps fixed = [a for a in al if a.fixed] if len(fixed) > 0: groupLines = makeGroupLines(fixed, 'freezeatoms') script.write(groupLines) script.write( 'fix freeze freezeatoms setforce 0.0 0.0 0.0') script.write('\n') # sample commands script.write('\n') script.write('#### output the (wrapped) coordinates \n') script.write( '# dump 1 all custom 100 dump.lammpstrj id type x y z vx vy vz \n' ) script.write('# dump_modify 1 sort id \n') script.write('\n') script.write('#### minimization \n') script.write('# minimize 0.0 0.0 100 10000 \n') script.write('\n') script.write('#### initialization of velocities \n') script.write( '# velocity all create 300.0 4928459 mom yes rot yes dist gaussian\n' ) script.write('\n') script.write('#### nve run \n') script.write('# timestep 1 \n') script.write('# fix 1 all nve \n') script.write('# run 1000 \n') script.write(' \n') script.write('#### write restart file (* gets replaced by timestep)\n') script.write('# write_restart restart.*\n') script.write(' \n') # writing the data file with open(filedata, 'w') as out: # header of the data file out.write('Generated by prepLammps.py, %s@%s on %s\n\n' % (os.getenv('LOGNAME'), os.getenv('HOSTNAME'), time.strftime('%X %x %Z'))) out.write('%d atoms\n' % len(al)) out.write('%d bonds\n' % len(st.bonds)) out.write('%d angles\n' % len(st.angles)) out.write('%d dihedrals\n' % len(st.torsions)) out.write('%d impropers\n\n' % len(st.inversions)) out.write('%d atom types\n' % len(st.sortedAtomLabels)) out.write('%d bond types\n' % len(st.sortedBondTypes)) out.write('%d angle types\n' % len(st.sortedAngleTypes)) out.write('%d dihedral types\n' % len(st.sortedTorsionTypes)) out.write('%d improper types\n\n' % len(st.sortedInversionTypes)) out.write('%f %f xlo xhi\n' % (cell[0], cell[1])) out.write('%f %f ylo yhi\n' % (cell[2], cell[3])) out.write('%f %f zlo zhi\n' % (cell[4], cell[5])) if len(cell) == 9: out.write('%f %f %f xy xz yz\n' % (cell[6], cell[7], cell[8])) # atom types out.write('\nMasses\n\n') for i, b in enumerate(st.sortedAtomLabels): bt = ff.atomTypes[b] out.write('%d %f # %s\n' % (i + 1, bt.mass, b)) # vdw parameters and hydrogen bonds parameters # bond Types if not pairStyleHybrid: out.write('\nPair Coeffs\n\n') for i, b in enumerate(st.sortedAtomLabels): bt = ff.atomTypes[b] out.write('%d %s # %s\n' % (i + 1, bt.lammps(), b)) # bond Types if len(st.sortedBondTypes) > 0: out.write('\nBond Coeffs\n\n') for i, bi in enumerate(st.sortedBondTypes): out.write('%d %s\n' % (i + 1, bi.lammps())) # angle Types if len(st.sortedAngleTypes) > 0: out.write('\nAngle Coeffs\n\n') for i, bi in enumerate(st.sortedAngleTypes): out.write('%d %s\n' % (i + 1, bi.lammps())) # torsion Types if len(st.sortedTorsionTypes) > 0: out.write('\nDihedral Coeffs\n\n') for i, bi in enumerate(st.sortedTorsionTypes): out.write('%d %s\n' % (i + 1, bi.lammps())) # inversion Types if len(st.sortedInversionTypes) > 0: out.write('\nImproper Coeffs\n\n') for i, bi in enumerate(st.sortedInversionTypes): out.write('%d %s\n' % (i + 1, bi.lammps())) # atoms out.write('\nAtoms\n\n') for a in al: atomtypeindex = st.usedAtomLabels[a.ffType] + 1 out.write('%d 0 %d %.10f %.10f %.10f %.10f # %s\n' % (a.aNo, atomtypeindex, a.charge, a.xyz[0], a.xyz[1], a.xyz[2], a)) # bonds out.write('\nBonds\n\n') for i, bi in enumerate(st.bonds): out.write( '%d %d %d %d\n' % (i + 1, st.usedBondTypes[bi.type] + 1, bi.i.aNo, bi.j.aNo)) # angles out.write('\nAngles\n\n') for i, bi in enumerate(st.angles): out.write('%d %d %d %d %d\n' % (i + 1, st.usedAngleTypes[bi.type] + 1, bi.i.aNo, bi.j.aNo, bi.k.aNo)) # torsion out.write('\nDihedrals\n\n') for i, bi in enumerate(st.torsions): out.write('%d %d %d %d %d %d\n' % (i + 1, st.usedTorsionTypes[bi.type] + 1, bi.i.aNo, bi.j.aNo, bi.k.aNo, bi.l.aNo)) # inversions out.write('\nImpropers\n\n') for i, bi in enumerate(st.inversions): if bi.type.type == 'amber': out.write('%d %d %d %d %d %d\n' % (i + 1, st.usedInversionTypes[bi.type] + 1, bi.j.aNo, bi.k.aNo, bi.i.aNo, bi.l.aNo)) elif bi.type.type == 'dreiding': out.write('%d %d %d %d %d %d\n' % (i + 1, st.usedInversionTypes[bi.type] + 1, bi.i.aNo, bi.j.aNo, bi.k.aNo, bi.l.aNo)) else: print >> sys.stderr, 'Unknown improper type for lammps (probably unimplemented yet) %s ' % bi.type.type sys.exit(1) if debug: print 'done writing lammps input and datafiles: %s, %s' % (filescript, filedata) return st
# This module contains classess responsible for creating game characters from random import sample import structure as st # Create maze instance maze = st.Structure() class Hero: """Generates hero instance and controls his mouvements""" def __init__(self): """Define properties of the hero""" self.width = 32 self.height = 40 # Putting MacGyver at the center of the entrance spot self.distance_to_horizontal_edge = (maze.sprite_dimension - self.width) / 2 self.distance_to_vertical_edge = (maze.sprite_dimension - self.height) / 2 self.x = maze.entrance[0][0] + self.distance_to_horizontal_edge self.y = maze.entrance[0][1] + self.distance_to_vertical_edge # MacGyver move by a step equal to sprite dimension self.speed = maze.sprite_dimension self.image = st.pygame.image.load("MacGyver.png") self.start_position = (self.x, self.y) # The following functions define four possible mouvements. # Each mouvement function, draws a BLACK rectangle in the previous position # This will allow to hide objects after collecting them
def writeTopology(fileName, AL, FF, debug=False, exceptResidues=[]): """write topology to prmtop file""" if debug: print 'Writing amber topology file %s...' % fileName # get ready for amber ST = structure.Structure(AL, FF, debug=debug, exceptResidues=exceptResidues) residueList = makeResidueList(AL) numberExcludedAtoms, excludedAtoms = getExcludedAtoms(AL) bondsWithH = filter(hasHydrogenBond, ST.bonds) anglesWithH = filter(hasHydrogenAngle, ST.angles) torsionsWithH = filter(hasHydrogenTorsion, ST.torsions) inversionsWithH = filter(hasHydrogenInversion, ST.inversions) bondsWithoutH = filter(nothasHydrogenBond, ST.bonds) anglesWithoutH = filter(nothasHydrogenAngle, ST.angles) torsionsWithoutH = filter(nothasHydrogenTorsion, ST.torsions) inversionsWithoutH = filter(nothasHydrogenInversion, ST.inversions) with open(fileName, 'w') as f: f.write( '%%VERSION VERSION_STAMP = V0001.000 DATE = %s \n' % time.strftime('%x %X')) f.write( '%FLAG TITLE \n' ) f.write( '%FORMAT(20a4) \n' ) f.write( 'title \n' ) f.write( '%FLAG POINTERS \n' ) f.write( '%FORMAT(10I8) \n' ) NATOM = len(AL) # total number of atoms NTYPES = len(ST.usedAtomLabels) # total number of distinct atom types NBONH = len(bondsWithH) # number of bonds containing hydrogen MBONA = len(bondsWithoutH) # number of bonds not containing hydrogen NTHETH = len(anglesWithH) # number of angles containing hydrogen MTHETA = len( anglesWithoutH) # number of angles not containing hydrogen NPHIH = len(torsionsWithH) + len( inversionsWithH) # number of dihedrals containing hydrogen MPHIA = len(torsionsWithoutH) + len( inversionsWithoutH) # number of dihedrals not containing hydrogen NHPARM = 0 # currently not used NPARM = 0 # used to determine if addles created prmtop NNB = len(excludedAtoms) # number of excluded atoms NRES = len(residueList) # number of residues NBONA = MBONA # MBONA + number of constraint bonds NTHETA = MTHETA # MTHETA + number of constraint angles NPHIA = MPHIA # MPHIA + number of constraint dihedrals NUMBND = len(ST.sortedBondTypes) # number of unique bond types NUMANG = len(ST.sortedAngleTypes) # number of unique angle types NPTRA = len(ST.sortedTorsionTypes) + len( ST.sortedInversionTypes) # number of unique dihedral types NATYP = 1 # number of atom types in parameter file, see SOLTY below NPHB = 1 # number of distinct 10-12 hydrogen bond pair types IFPERT = 0 # set to 1 if perturbation info is to be read in NBPER = 0 # number of bonds to be perturbed NGPER = 0 # number of angles to be perturbed NDPER = 0 # number of dihedrals to be perturbed MBPER = 0 # number of bonds with atoms completely in perturbed group MGPER = 0 # number of angles with atoms completely in perturbed group MDPER = 0 # number of dihedrals with atoms completely in perturbed groups IFBOX = 0 # set to 1 if standard periodic box, 2 when truncated octahedral, 0 when there is no box NMXRS = len(AL) # number of atoms in the largest residue ??????? IFCAP = 0 # set to 1 if the CAP option from edit was specified NUMEXTRA = 0 # number of extra points found in topology # NCOPY = int(f.read(8)) # number of PIMD slices / number of beads f.write('%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d\n' % ( NATOM, NTYPES, NBONH, MBONA, NTHETH, MTHETA, NPHIH, MPHIA, NHPARM, NPARM, )) f.write('%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d\n' % ( NNB, NRES, NBONA, NTHETA, NPHIA, NUMBND, NUMANG, NPTRA, NATYP, NPHB, )) f.write('%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d\n' % ( IFPERT, NBPER, NGPER, NDPER, MBPER, MGPER, MDPER, IFBOX, NMXRS, IFCAP, )) f.write('%8d\n' % (NUMEXTRA)) f.write( '%FLAG ATOM_NAME \n' ) f.write( '%FORMAT(20a4) \n' ) for i in range(len(AL)): f.write('%-4.4s' % AL[i].aName) if (i + 1) % 20 == 0: f.write('\n') if len(AL) % 20 != 0: f.write('\n') f.write( '%FLAG CHARGE \n' ) f.write( '%FORMAT(5E16.8) \n' ) for i in range(len(AL)): f.write('%16.8E' % (AL[i].charge * 18.2223)) if (i + 1) % 5 == 0: f.write('\n') if len(AL) % 5 != 0: f.write('\n') f.write( '%FLAG MASS \n' ) f.write( '%FORMAT(5E16.8) \n' ) for i in range(len(AL)): f.write('%16.8E' % FF.atomTypes[AL[i].ffType].mass) if (i + 1) % 5 == 0: f.write('\n') if len(AL) % 5 != 0: f.write('\n') f.write( '%FLAG ATOM_TYPE_INDEX \n' ) f.write( '%FORMAT(10I8) \n' ) for i in range(len(AL)): label = AL[i].ffType labelindex = ST.usedAtomLabels[label] f.write('%8d' % (labelindex + 1)) if (i + 1) % 10 == 0: f.write('\n') if len(AL) % 10 != 0: f.write('\n') f.write( '%FLAG NUMBER_EXCLUDED_ATOMS \n' ) f.write( '%FORMAT(10I8) \n' ) for i in range(len(AL)): f.write('%8d' % numberExcludedAtoms[i]) if (i + 1) % 10 == 0: f.write('\n') if len(AL) % 10 != 0: f.write('\n') f.write( '%FLAG NONBONDED_PARM_INDEX \n' ) f.write( '%FORMAT(10I8) \n' ) array = [0] * (NTYPES * NTYPES) for i in range(1, NTYPES + 1): for j in range(1, NTYPES + 1): index = NTYPES * (i - 1) + j a = max(i, j) b = min(i, j) array[index - 1] = b + a * (a - 1) / 2 data = array for i in range(len(data)): f.write('%8d' % data[i]) if (i + 1) % 10 == 0: f.write('\n') if len(data) % 10 != 0: f.write('\n') f.write( '%FLAG RESIDUE_LABEL \n' ) f.write( '%FORMAT(20a4) \n' ) for i in range(len(residueList)): f.write('%-4s' % AL[residueList[i] - 1].rName) if (i + 1) % 20 == 0: f.write('\n') if len(residueList) % 20 != 0: f.write('\n') f.write( '%FLAG RESIDUE_POINTER \n' ) f.write( '%FORMAT(10I8) \n' ) for i in range(len(residueList)): f.write('%8d' % residueList[i]) if (i + 1) % 10 == 0: f.write('\n') if len(residueList) % 10 != 0: f.write('\n') f.write( '%FLAG BOND_FORCE_CONSTANT \n' ) f.write( '%FORMAT(5E16.8) \n' ) for i in range(len(ST.sortedBondTypes)): f.write('%16.8E' % (ST.sortedBondTypes[i].K / 2.0)) if (i + 1) % 5 == 0: f.write('\n') if len(ST.sortedBondTypes) % 5 != 0 or len(ST.sortedBondTypes) == 0: f.write('\n') f.write( '%FLAG BOND_EQUIL_VALUE \n' ) f.write( '%FORMAT(5E16.8) \n' ) for i in range(len(ST.sortedBondTypes)): f.write('%16.8E' % ST.sortedBondTypes[i].R) if (i + 1) % 5 == 0: f.write('\n') if len(ST.sortedBondTypes) % 5 != 0 or len(ST.sortedBondTypes) == 0: f.write('\n') f.write( '%FLAG ANGLE_FORCE_CONSTANT \n' ) f.write( '%FORMAT(5E16.8) \n' ) for i in range(len(ST.sortedAngleTypes)): f.write('%16.8E' % (ST.sortedAngleTypes[i].K / 2.0)) if (i + 1) % 5 == 0: f.write('\n') if len(ST.sortedAngleTypes) % 5 != 0 or len(ST.sortedAngleTypes) == 0: f.write('\n') f.write( '%FLAG ANGLE_EQUIL_VALUE \n' ) f.write( '%FORMAT(5E16.8) \n' ) for i in range(len(ST.sortedAngleTypes)): f.write('%16.8E' % (ST.sortedAngleTypes[i].theta0 / 180.0 * math.pi)) if (i + 1) % 5 == 0: f.write('\n') if len(ST.sortedAngleTypes) % 5 != 0 or len(ST.sortedAngleTypes) == 0: f.write('\n') f.write( '%FLAG DIHEDRAL_FORCE_CONSTANT \n' ) f.write( '%FORMAT(5E16.8) \n' ) numTor = len(ST.sortedTorsionTypes) numInv = len(ST.sortedInversionTypes) for i in range(numTor): f.write('%16.8E' % (ST.sortedTorsionTypes[i].K / 2.0)) if (i + 1) % 5 == 0: f.write('\n') for i in range(numInv): f.write('%16.8E' % (ST.sortedInversionTypes[i].amber())) if (i + 1 + numTor) % 5 == 0: f.write('\n') if (numTor + numInv) % 5 != 0 or (numTor + numInv) == 0: f.write('\n') f.write( '%FLAG DIHEDRAL_PERIODICITY \n' ) f.write( '%FORMAT(5E16.8) \n' ) numTor = len(ST.sortedTorsionTypes) numInv = len(ST.sortedInversionTypes) for i in range(numTor): f.write('%16.8E' % ST.sortedTorsionTypes[i].N) if (i + 1) % 5 == 0: f.write('\n') for i in range(numInv): f.write('%16.8E' % 2.0) if (i + 1 + numTor) % 5 == 0: f.write('\n') if (numTor + numInv) % 5 != 0 or (numTor + numInv) == 0: f.write('\n') f.write( '%FLAG DIHEDRAL_PHASE \n' ) f.write( '%FORMAT(5E16.8) \n' ) numTor = len(ST.sortedTorsionTypes) numInv = len(ST.sortedInversionTypes) for i in range(numTor): dToPhase(ST.sortedTorsionTypes[i].D) f.write('%16.8E' % (dToPhase(ST.sortedTorsionTypes[i].D) / 180.0 * math.pi)) if (i + 1) % 5 == 0: f.write('\n') for i in range(numInv): f.write('%16.8E' % (180.0 / 180.0 * math.pi)) if (i + 1 + numTor) % 5 == 0: f.write('\n') if (numTor + numInv) % 5 != 0 or (numTor + numInv) == 0: f.write('\n') f.write( '%FLAG SOLTY \n' ) f.write( '%FORMAT(5E16.8) \n' ) f.write('%16.8E\n' % 0.0) f.write( '%FLAG LENNARD_JONES_ACOEF \n' ) f.write( '%FORMAT(5E16.8) \n' ) array = [0] * (NTYPES * (NTYPES + 1) / 2) for a in range(1, NTYPES + 1): for b in range(1, a + 1): aT = FF.atomTypes[ST.sortedAtomLabels[a - 1]] bT = FF.atomTypes[ST.sortedAtomLabels[b - 1]] index = b + a * (a - 1) / 2 array[index - 1] = aT.mixWith(bT, FF.mean) data = array for i in range(len(data)): ac = data[i].vdwD * math.pow(data[i].vdwR, 12) f.write('%16.8E' % ac) if (i + 1) % 5 == 0: f.write('\n') if len(data) % 5 != 0: f.write('\n') f.write( '%FLAG LENNARD_JONES_BCOEF \n' ) f.write( '%FORMAT(5E16.8) \n' ) for i in range(len(data)): ac = 2.0 * data[i].vdwD * math.pow(data[i].vdwR, 6) f.write('%16.8E' % ac) if (i + 1) % 5 == 0: f.write('\n') if len(data) % 5 != 0: f.write('\n') f.write( '%FLAG BONDS_INC_HYDROGEN \n' ) f.write( '%FORMAT(10I8) \n' ) array = [0] * (3 * len(bondsWithH)) for i in range(len(bondsWithH)): b = bondsWithH[i] array[3 * i] = (b.i.aNo - 1) * 3 array[3 * i + 1] = (b.j.aNo - 1) * 3 array[3 * i + 2] = ST.usedBondTypes[b.type] + 1 for i in range(len(array)): f.write('%8d' % array[i]) if (i + 1) % 10 == 0: f.write('\n') if len(array) % 10 != 0 or len(array) == 0: f.write('\n') f.write( '%FLAG BONDS_WITHOUT_HYDROGEN \n' ) f.write( '%FORMAT(10I8) \n' ) array = [0] * (3 * len(bondsWithoutH)) for i in range(len(bondsWithoutH)): b = bondsWithoutH[i] array[3 * i] = (b.i.aNo - 1) * 3 array[3 * i + 1] = (b.j.aNo - 1) * 3 array[3 * i + 2] = ST.usedBondTypes[b.type] + 1 for i in range(len(array)): f.write('%8d' % array[i]) if (i + 1) % 10 == 0: f.write('\n') if len(array) % 10 != 0 or len(array) == 0: f.write('\n') f.write( '%FLAG ANGLES_INC_HYDROGEN \n' ) f.write( '%FORMAT(10I8) \n' ) array = [0] * (4 * len(anglesWithH)) for i in range(len(anglesWithH)): b = anglesWithH[i] array[4 * i] = (b.i.aNo - 1) * 3 array[4 * i + 1] = (b.j.aNo - 1) * 3 array[4 * i + 2] = (b.k.aNo - 1) * 3 array[4 * i + 3] = ST.usedAngleTypes[b.type] + 1 for i in range(len(array)): f.write('%8d' % array[i]) if (i + 1) % 10 == 0: f.write('\n') if len(array) % 10 != 0 or len(array) == 0: f.write('\n') f.write( '%FLAG ANGLES_WITHOUT_HYDROGEN \n' ) f.write( '%FORMAT(10I8) \n' ) array = [0] * (4 * len(anglesWithoutH)) for i in range(len(anglesWithoutH)): b = anglesWithoutH[i] array[4 * i] = (b.i.aNo - 1) * 3 array[4 * i + 1] = (b.j.aNo - 1) * 3 array[4 * i + 2] = (b.k.aNo - 1) * 3 array[4 * i + 3] = ST.usedAngleTypes[b.type] + 1 for i in range(len(array)): f.write('%8d' % array[i]) if (i + 1) % 10 == 0: f.write('\n') if len(array) % 10 != 0 or len(array) == 0: f.write('\n') f.write( '%FLAG DIHEDRALS_INC_HYDROGEN \n' ) f.write( '%FORMAT(10I8) \n' ) # there is minus on 3rd or 3rd and 4th atoms... # minus on the fourth atom means inversion # minus on the third atom meands not to include this 1-4 interaction lenWithH = len(torsionsWithH) array = [0] * (5 * lenWithH + 5 * len(inversionsWithH)) for i in range(lenWithH): b = torsionsWithH[i] array[5 * i] = (b.i.aNo - 1) * 3 array[5 * i + 1] = (b.j.aNo - 1) * 3 if b.avoid14: avoid14 = -1 else: avoid14 = 1 array[5 * i + 2] = (b.k.aNo - 1) * 3 * avoid14 array[5 * i + 3] = (b.l.aNo - 1) * 3 array[5 * i + 4] = ST.usedTorsionTypes[b.type] + 1 for i in range(lenWithH, lenWithH + len(inversionsWithH)): b = inversionsWithH[i - lenWithH] array[5 * i] = (b.j.aNo - 1) * 3 array[5 * i + 1] = (b.k.aNo - 1) * 3 array[5 * i + 2] = -(b.i.aNo - 1) * 3 array[5 * i + 3] = -(b.l.aNo - 1) * 3 array[5 * i + 4] = ST.usedInversionTypes[b.type] + 1 + numTor for i in range(len(array)): f.write('%8d' % array[i]) if (i + 1) % 10 == 0: f.write('\n') if len(array) % 10 != 0 or len(array) == 0: f.write('\n') f.write( '%FLAG DIHEDRALS_WITHOUT_HYDROGEN \n' ) f.write( '%FORMAT(10I8) \n' ) lenWithH = len(torsionsWithoutH) array = [0] * (5 * lenWithH + 5 * len(inversionsWithoutH)) for i in range(lenWithH): b = torsionsWithoutH[i] array[5 * i] = (b.i.aNo - 1) * 3 array[5 * i + 1] = (b.j.aNo - 1) * 3 if b.avoid14: avoid14 = -1 else: avoid14 = 1 array[5 * i + 2] = (b.k.aNo - 1) * 3 * avoid14 array[5 * i + 3] = (b.l.aNo - 1) * 3 array[5 * i + 4] = ST.usedTorsionTypes[b.type] + 1 for i in range(lenWithH, lenWithH + len(inversionsWithoutH)): b = inversionsWithoutH[i - lenWithH] array[5 * i] = (b.j.aNo - 1) * 3 array[5 * i + 1] = (b.k.aNo - 1) * 3 array[5 * i + 2] = -(b.i.aNo - 1) * 3 array[5 * i + 3] = -(b.l.aNo - 1) * 3 array[5 * i + 4] = ST.usedInversionTypes[b.type] + 1 + numTor for i in range(len(array)): f.write('%8d' % array[i]) if (i + 1) % 10 == 0: f.write('\n') if len(array) % 10 != 0 or len(array) == 0: f.write('\n') f.write( '%FLAG EXCLUDED_ATOMS_LIST \n' ) f.write( '%FORMAT(10I8) \n' ) data = excludedAtoms for i in range(len(data)): f.write('%8d' % data[i]) if (i + 1) % 10 == 0: f.write('\n') if len(data) % 10 != 0: f.write('\n') f.write( '%FLAG HBOND_ACOEF \n' ) f.write( '%FORMAT(5E16.8) \n' ) f.write(' 0.00000000E+00\n') f.write( '%FLAG HBOND_BCOEF \n' ) f.write( '%FORMAT(5E16.8) \n' ) f.write(' 0.00000000E+00\n') f.write( '%FLAG HBCUT \n' ) f.write( '%FORMAT(5E16.8) \n' ) f.write(' 0.00000000E+00\n') f.write( '%FLAG AMBER_ATOM_TYPE \n' ) f.write( '%FORMAT(20a4) \n' ) data = AL for i in range(len(data)): f.write('%-4s' % data[i].ffType) if (i + 1) % 20 == 0: f.write('\n') if len(data) % 20 != 0: f.write('\n') f.write( '%FLAG TREE_CHAIN_CLASSIFICATION \n' ) f.write( '%FORMAT(20a4) \n' ) # just filling crap !!!!!! data = AL for i in range(len(data)): f.write('BLA ') if (i + 1) % 20 == 0: f.write('\n') if len(data) % 20 != 0: f.write('\n') f.write( '%FLAG JOIN_ARRAY \n' ) f.write( '%FORMAT(10I8) \n' ) data = AL for i in range(len(data)): f.write(' 0') if (i + 1) % 10 == 0: f.write('\n') if len(data) % 10 != 0: f.write('\n') f.write( '%FLAG IROTAT \n' ) f.write( '%FORMAT(10I8) \n' ) data = AL for i in range(len(data)): f.write(' 0') if (i + 1) % 10 == 0: f.write('\n') if len(data) % 10 != 0: f.write('\n') #f.write('%FLAG BOX_DIMENSIONS \n') #f.write('%FORMAT(5E16.8) \n') #f.write(' 9.00000000E+01 5.62095570E+01 5.66096690E+01 6.77711270E+01\n') f.write( '%FLAG RADIUS_SET \n' ) f.write( '%FORMAT(1a80) \n' ) f.write( 'modified Bondi radii (mbondi) \n' ) f.write( '%FLAG RADII \n' ) f.write( '%FORMAT(5E16.8) \n' ) # just filling crap !!!!!! data = AL for i in range(len(data)): f.write('%16.8E' % 0.0) if (i + 1) % 5 == 0: f.write('\n') if len(data) % 5 != 0: f.write('\n') f.write( '%FLAG SCREEN \n' ) f.write( '%FORMAT(5E16.8) \n' ) # just filling crap !!!!!! data = AL for i in range(len(data)): f.write('%16.8E' % 0.0) if (i + 1) % 5 == 0: f.write('\n') if debug: print '%d atoms written to %s.' % (len(AL), fileName)
def read_xml( path='/Users/massimosferza/LRZ Sync+Share/TUM/TUM SoSe16/Courses/Software Lab/Git_repository/no-block-example.xml' ): """It creates a structure object for the OoD problem to solve, given a proper .xml file""" # create a tree object, given the correct address of the .xml file tree = et.parse(path) # create a variable that contains the root root = tree.getroot() ############################################################# # create a structure new_structure = structure.Structure() ############################################################# # create all the loadpaths # loop over the element <level> </level> contained in root for level in root.iter('level'): # create a loadpath level_id = int(level.find('id').text) loadpath_obj = lp.Loadpath(level_id) ############################################################# # add nodes to each loadpath for component in level.iter('component'): # for every component in the level, get x1 x_position = float(component.find('x1').text) # check if the loadpath already contains a node corresponding to x1 already_contained = False for node in loadpath_obj.node_list: if x_position == node.x_position: already_contained = True break if not already_contained: # if not add it loadpath_obj.node_list.append(nd.Node(x_position)) # for every component, that is not a connection if not 'X' in component.find('name').text: # get also x2 x_position = float(component.find('x2').text) # and again # check if the loadpath already contains a node corresponding to # x2 already_contained = False for node in loadpath_obj.node_list: if x_position == node.x_position: already_contained = True break if not already_contained: # if not add it loadpath_obj.node_list.append(nd.Node(x_position)) ############################################################# # add members to each loadpath for component in level.iter('component'): # for every component, that is not a connection if not 'X' in component.find('name').text: # get the previously created nodes x1 = float(component.find('x1').text) x2 = float(component.find('x2').text) for node in loadpath_obj.node_list: if x1 == node.x_position: node1 = node if x2 == node.x_position: node2 = node # create a member member_obj = c.Component( component.find('name').text, node1, node2, float(component.find('defoLength').text), float(component.find('defoRatio').text)) # add the member to the loadpath loadpath_obj.component_list.append(member_obj) # add the loadpath to the structure new_structure.path_list.append(loadpath_obj) ############################################################# # neglect all the connectionpaths ############################################################# return new_structure
def read_poscar(filename): """ Reads VASP POSCAR files, and returns VASP object, currently only cartesian coordinates are supported Input VASP file must be in the following format (Cartesian POSCAR output using VESTA, http://jp-minerals.org/vesta/en/, will suffice). Whitespaces are not important: Ni1 O2 1.0 4.8754000664 0.0000000000 0.0000000000 0.0000000000 2.8141000271 0.0000000000 -3.2680774749 0.0000000000 4.5253056414 Ni O 2 4 Cartesian 0.000000000 0.000000000 0.000000000 2.437700033 1.407050014 0.000000000 1.648646319 0.000000000 1.045345631 -0.041323873 0.000000000 3.479960010 4.086346498 1.407050014 1.045345631 -2.479023761 1.407050014 3.479960010 """ filename=os.path.abspath(filename) with open(filename) as f: lines = f.read().splitlines() comment = lines[0] scale = lines[1] lattice = [[float(x) for x in lines[2].split()], [float(x) for x in lines[3].split()], [float(x) for x in lines[4].split()]] if not isinstance(lines[5], str): """If the fifth line is string, it means that there are no species information""" error("No species information in the POSCAR") species_strs = lines[5].split() species_counts=[int(x) for x in lines[6].split()] if len(species_strs) != len(species_counts): error("Number of species and number of species strings do not match") species = [] for i in range(0, len(species_counts)): species += [species_strs[i]] * species_counts[i] iscartesian = [] if lines[7].startswith("C") or lines[7].startswith("c"): iscartesian = True elif lines[7].startswith("R") or lines[7].startswith("D") or lines[7].startswith("r") or lines[7].startswith("d"): iscartesian = False else: error("Coordinates are not Cartesian or Reciprocal!") coords = [] if iscartesian: for i in range(8,len(lines)): coords += [[float(x) for x in lines[i].split()[0:3]]] else: for i in range(8,len(lines)): coords += [[float(x) for x in lines[i].split()[0:3]]] #Dot product with the lattice, always print Cartesian crd=np.dot(np.array(coords),np.array(lattice)) coords=crd.tolist() return Vasp(comment=comment, scale=scale, struct=structure.Structure(lattice=lattice, species=species, coords=coords), iscartesian=iscartesian)