[docs]defparse(self,include_dir='/usr/local/gromacs/share/gromacs/top/',infer_system=True,**kwargs):"""Parse ITP file into Topology Parameters ---------- include_dir: str, optional A directory in which to look for other files included from the original file, if the files are not first found in the current directory. Default: "/usr/local/gromacs/share/gromacs/top/" infer_system: bool, optional (default True) If a ``[ molecules ]`` directive is not found within the the topology file, create a Topology with one of every ``[ moleculetype ]`` defined. If a ``[ molecules ]`` directive is found, this keyword is ignored. Returns ------- MDAnalysis *Topology* object """self.molecules={}self._molecules=[]# for orderself.current_mol=Noneself.parser=self._passself.system_molecules=[]# Open and check itp validitywithopenany(self.filename)asitpfile:self.lines=GmxTopIterator(itpfile,include_dir,kwargs)forlineinself.lines:if'['inlineand']'inline:section=line.split('[')[1].split(']')[0].strip()ifsection=='moleculetype':self.parser=self.parse_moleculetypeelifsection=='molecules':self.parser=self.parse_moleculeselifself.current_mol:self.parser=self.current_mol.parsers.get(section,self._pass)else:self.parser=self._passelse:self.parser(line)ifnotself.system_moleculesandinfer_system:self.system_molecules=[x.nameforxinself._molecules]self.build_system()attrs=[]# atom stuffforvals,Attr,dtypein((self.ids,Atomids,np.int32),(self.types,Atomtypes,object),(self.names,Atomnames,object),(self.chargegroups,Chargegroups,np.int32),(self.charges,Charges,np.float32),):ifall(vals):attrs.append(Attr(np.array(vals,dtype=dtype)))ifnotall(self.masses):masses=guessers.guess_masses(self.types)attrs.append(Masses(masses,guessed=True))else:attrs.append(Masses(np.array(self.masses,dtype=np.float64)))# residue stuffresids=np.array(self.resids,dtype=np.int32)resnames=np.array(self.resnames,dtype=object)molnums=np.array(self.molnums,dtype=np.int32)attrs.append(Resids(resids))attrs.append(Resnums(resids.copy()))attrs.append(Resnames(resnames))attrs.append(Moltypes(np.array(self.moltypes,dtype=object)))attrs.append(Molnums(molnums))n_atoms=len(self.ids)n_residues=len(self.resids)n_segments=len(self.system_molecules)attrs.append(Segids(np.array(self.system_molecules,dtype=object)))segidx=molnums-1top=Topology(n_atoms,n_residues,n_segments,attrs=attrs,atom_resindex=self.residx,residue_segindex=segidx)# connectivity stufffordct,Attr,attrnamein((self.bonds,Bonds,'bonds'),(self.angles,Angles,'angles'),(self.dihedrals,Dihedrals,'dihedrals'),(self.impropers,Impropers,'impropers')):ifdct:indices,types=zip(*list(dct.items()))else:indices,types=[],[]types=[reduce_singular(t)fortintypes]tattr=Attr(indices,types=types)top.add_TopologyAttr(tattr)returntop