/// <summary>Static data initialization.</summary> static AtomNameExtensions() { Type enumType = typeof(AtomName); ICollection <AtomName> allContainerAtoms = new HashSet <AtomName>(); AtomNameForAtomType = new Dictionary <uint, AtomName>(); AtomAttributesForAtomName = new Dictionary <AtomName, AtomAttributes>(); allContainerAtoms.Add(AtomName.Root); // Use reflection to find the attributes describing the codec identifiers foreach (AtomName atomName in Enum.GetValues(enumType)) { string name = Enum.GetName(enumType, atomName); FieldInfo fieldInfo = enumType.GetField(name); AtomAttribute[] attributes = (AtomAttribute[])fieldInfo.GetCustomAttributes(typeof(AtomAttribute), false); if (atomName == AtomName.Root) { // The root container has no metadata and does not occur in any other atom AtomAttributesForAtomName.Add(atomName, new AtomAttributes(new uint[0], AtomFlags.Container, new AtomName[0])); } else if (attributes != null && attributes.Length == 1) { AtomAttributes atomAttributes = GetAtomAttributes(atomName, attributes[0], allContainerAtoms); AtomAttributesForAtomName.Add(atomName, atomAttributes); // List all 4CC for this atom foreach (uint atomType in atomAttributes.AtomTypes) { Debug.Assert(!AtomNameForAtomType.ContainsKey(atomType), string.Format("Duplicate 4CC '{0}'", atomType.ToString4CC())); AtomNameForAtomType.Add(atomType, atomName); } } else { Debug.Fail(string.Format("No attributes for {0}. Please add attributes to the AtomName enumeration.", atomName)); } } CheckSuitableParents(); }
public void InitialStep() { Debug.Log("Inside Initial Step"); //CSharpLibrary.CSharpLibrary.la var lmp_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(System.IntPtr))); CSharpLibrary.CSharpLibrary.lammps_open_no_mpi(0, System.IntPtr.Zero, lmp_ptr); var deref1 = (System.IntPtr)Marshal.PtrToStructure(lmp_ptr, typeof(System.IntPtr)); Debug.Log("Lammps Pointer: " + deref1); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "# package omp 40"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "# suffix omp"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "variable xx equal 20"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "variable yy equal 20"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "variable zz equal 20"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "units lj"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "boundary p p p"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "atom_style atomic"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "lattice fcc 0.8442"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "region box block 0 ${xx} 0 ${yy} 0 ${zz}"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "create_box 1 box"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "create_atoms 1 box"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "mass 1 1.0"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "velocity all create 10 87287 loop geom"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "neighbor 0.3 bin"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "neigh_modify delay 0 every 20 check no"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "pair_style lj/cut 2.5"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "pair_coeff 1 1 1.0 1.0 2.5"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "fix 1 all nve"); CSharpLibrary.CSharpLibrary.lammps_command(deref1, "run 0"); // Debug.Log(CSharpLibrary.CSharpLibrary.lammps_command(deref1, "run 100000 pre no post no")); System.IntPtr natmPtr = CSharpLibrary.CSharpLibrary.lammps_extract_global(deref1, "natoms"); nAtom = (int)Marshal.PtrToStructure(natmPtr, typeof(int)); Debug.Log(nAtom); atoms = new AtomAttributes[nAtom]; Double[] temp = new Double[3]; System.IntPtr[] PointerToFloat = new IntPtr[nAtom]; System.IntPtr posPtr; for (int j = 0; j < nFrame; j++) { if (j > 0) { CSharpLibrary.CSharpLibrary.lammps_command(deref1, "run 1 pre no post no"); natmPtr = CSharpLibrary.CSharpLibrary.lammps_extract_global(deref1, "natoms"); nAtom = (int)Marshal.PtrToStructure(natmPtr, typeof(int)); } posPtr = CSharpLibrary.CSharpLibrary.lammps_extract_atom(deref1, "x"); Marshal.Copy(posPtr, PointerToFloat, 0, nAtom); for (int i = 0; i < nAtom; i++) { Marshal.Copy(PointerToFloat[i], temp, 0, 3); double[] rr = new double[3] { temp[0] / 2, temp[1] / 2, temp[2] / 2 }; AtomAttributes at = new AtomAttributes("C", rr); if (j == 0) { atoms[i] = at; } else if (j > 0) { atoms[i].framePos.Add(new Vector3((float)temp[0] / 2, (float)temp[1] / 2, (float)temp[2] / 2)); } } readFrameCounter++; } CSharpLibrary.CSharpLibrary.lammps_close(deref1); Marshal.FreeHGlobal(lmp_ptr); lmp_ptr = System.IntPtr.Zero; }
public void ReadFile(StreamReader sr) { Regex reg = new Regex(@"\s+"); int atomIndex = 0; using (sr) { string line = sr.ReadLine().Trim(); Debug.Log("Line: " + line + "\n"); string[] cdnt = reg.Split(line); Debug.Log("FirstLine: " + cdnt + "\n"); numAtoms = int.Parse(cdnt[0]); Debug.Log(numAtoms); atoms = new AtomAttributes[numAtoms]; //Get information about the box line = sr.ReadLine().Trim(); cdnt = reg.Split(line); Debug.Log("Second Line: " + line); for (int index = 0; index < cdnt.Length; index += 1) { Debug.Log("Second Line: " + index + " " + cdnt[index]); } for (int index = 0; index < 3; index++) { l[index] = float.Parse(cdnt[index]); angle[index] = float.Parse(cdnt[index + 3]); } while ((line = sr.ReadLine()) != null) { cdnt = reg.Split(line.Trim()); if (cdnt.Length < 4) { continue; } if (cdnt.Length >= 4) { double[] rr = new double[3] { float.Parse(cdnt[1]), float.Parse(cdnt[2]), float.Parse(cdnt[3]) }; if (rotation[0] + rotation[1] + rotation[2] != 0) { rr = rotateMatrix(rotation[0], rotation[1], rotation[2], rr); } for (int j = 0; j < 3; j++) { if ((double.Parse(cdnt[j + 1]) < minPos[j]) || (atomIndex == 0)) { minPos[j] = double.Parse(cdnt[j + 1]); } if ((double.Parse(cdnt[j + 1]) > maxPos[j]) || (atomIndex == 0)) { maxPos[j] = double.Parse(cdnt[j + 1]); } } AtomAttributes at = new AtomAttributes(cdnt[0], rr); Debug.Log(atomIndex + " : " + rr[0] + " , " + rr[1] + " , " + rr[2]); if (cdnt.Length == 5) { at.stress = double.Parse(cdnt[4]); } Debug.Log(atomIndex + " : " + numAtoms); atoms[atomIndex] = at; atomIndex++; } } } }
public void ReadFile() { Regex reg = new Regex(@"\s+"); int atomIndex = 0; using (StreamReader sr = new StreamReader(filePath)) { string line = sr.ReadLine().Trim(); //Debug.Log("Line: " + line + "\n"); string[] cdnt = reg.Split(line); //Debug.Log("FirstLine: " + cdnt+"\n"); numAtoms = int.Parse(cdnt[0]); atoms = new AtomAttributes[numAtoms]; //Get information about the box line = sr.ReadLine().Trim(); cdnt = reg.Split(line); /* * Debug.Log("Second Line: " + line); * for(int index = 0;index < cdnt.Length; index+=1) * Debug.Log("Second Line: " + index +" "+cdnt[index]); */ for (int index = 0; index < 3; index++) { l[index] = float.Parse(cdnt[index]); angle[index] = float.Parse(cdnt[index + 3]); } while ((line = sr.ReadLine()) != null) { cdnt = reg.Split(line); if (cdnt.Length == 5) { isCol5 = true; } if (cdnt.Length < 4) { continue; } else { double[] rr = new double[3] { float.Parse(cdnt[1]), float.Parse(cdnt[2]), float.Parse(cdnt[3]) }; for (int j = 0; j < 3; j++) { if ((double.Parse(cdnt[j + 1]) < minPos[j]) || (atomIndex == 0)) { minPos[j] = double.Parse(cdnt[j + 1]); } if ((double.Parse(cdnt[j + 1]) > maxPos[j]) || (atomIndex == 0)) { maxPos[j] = double.Parse(cdnt[j + 1]); } } AtomAttributes at = new AtomAttributes(cdnt[0], rr); if (isCol5) { at.stress = int.Parse(cdnt[4]); } atoms[atomIndex] = at; atomIndex++; //Debug.Log(atoms[atomIndex].iatom+" , "+atoms[atomIndex].rr0[0] + " , " + atoms[atomIndex].rr0[1] + " , " + atoms[atomIndex].rr0[2]); } } } }
public void ReadFile(string fileName = null) { Regex reg = new Regex(@"\s+"); int atomIndex = 0; if (fileName == null) { fileName = filePath; } Debug.Log(fileName); TextAsset textAsset = Resources.Load(fileName) as TextAsset; byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(textAsset.text); MemoryStream stream = new MemoryStream(byteArray); StreamReader sr = new StreamReader(stream); { string line = sr.ReadLine().Trim(); Debug.Log("Line: " + line + "\n"); string[] cdnt = reg.Split(line); Debug.Log("FirstLine: " + cdnt + "\n"); numAtoms = int.Parse(cdnt[0]); Debug.Log(numAtoms); atoms = new AtomAttributes[numAtoms]; //Get information about the box line = sr.ReadLine().Trim(); cdnt = reg.Split(line); Debug.Log("Second Line: " + line); for (int index = 0; index < cdnt.Length; index += 1) { Debug.Log("Second Line: " + index + " " + cdnt[index]); } for (int index = 0; index < 3; index++) { l[index] = float.Parse(cdnt[index]); angle[index] = float.Parse(cdnt[index + 3]); } while ((line = sr.ReadLine()) != null) { cdnt = reg.Split(line.Trim()); if (cdnt.Length < 4) { continue; } if (cdnt.Length >= 4) { double[] rr = new double[3] { float.Parse(cdnt[1]), float.Parse(cdnt[2]), float.Parse(cdnt[3]) }; if (rotation[0] + rotation[1] + rotation[2] != 0) { rr = rotateMatrix(rotation[0], rotation[1], rotation[2], rr); } for (int j = 0; j < 3; j++) { if ((double.Parse(cdnt[j + 1]) < minPos[j]) || (atomIndex == 0)) { minPos[j] = double.Parse(cdnt[j + 1]); } if ((double.Parse(cdnt[j + 1]) > maxPos[j]) || (atomIndex == 0)) { maxPos[j] = double.Parse(cdnt[j + 1]); } } AtomAttributes at = new AtomAttributes(cdnt[0], rr); Debug.Log(atomIndex + " : " + rr[0] + " , " + rr[1] + " , " + rr[2]); if (cdnt.Length == 5) { at.stress = double.Parse(cdnt[4]); } Debug.Log(atomIndex + " : " + numAtoms); atoms[atomIndex] = at; atomIndex++; } } } }