public WindowInfoObserver( ITextLogger textLogger = null, int dueTime = 0, int periodMilliseconds = 1000) : base(textLogger, dueTime, periodMilliseconds) { }
public void AddTextLogger(ITextLogger logger) { lock (_autoFlushSync) { // pause auto flush while adding a new logger _textLoggers.Add(logger); } StartAutoFlushThread(); }
public static Nonbonded FromString(string line, ITextLogger logger) { Element elem = Element.FromString(line, 1, 6); //Debug.Assert(0 == elem.parms[0]); // "FE 0.010000 0.000000 0.650000" happens if (!(0 == elem.parms[0])) { logger.Log(string.Format("Warning: Nonbonded params ({0}): 1st parameter should be in general == 0", line)); } double epsilon = elem.parms[1]; double Rmin2 = elem.parms[2]; //Debug.Assert(Rmin2 > 0); if (!(Rmin2 > 0)) { logger.Log(string.Format("Error : Nonbonded params ({0}): 3rd parameter (Rmin2) must be '> 0'", line)); } double eps_14 = double.NaN; double Rmin2_14 = double.NaN; if (elem.parms.Length > 3) { HDebug.Assert(0 == elem.parms[3]); eps_14 = elem.parms[4]; Rmin2_14 = elem.parms[5]; //Debug.Assert(Rmin2_14 > 0); if (!(Rmin2_14 > 0)) { logger.Log(string.Format("Error : Nonbonded params ({0}): 6th parameter (Rmin2_14) must be '> 0'", line)); } } Nonbonded nonbonded = new Nonbonded(line, elem.types, epsilon, Rmin2, eps_14, Rmin2_14); return(nonbonded); }
protected ValueObserverBase(ITextLogger textLogger = null) { this.ValueChangeEvent = new EventContainer <ValueChangedEventArg <TValue> >( handler => this.ValueChange += handler, handler => this.ValueChange -= handler); this.TextLogger = textLogger; }
public Nonbonded FindNonbonded(string type0, ITextLogger logger) { if (_FindNonbonded.ContainsKey(type0) == false) { Nonbonded found = null; foreach (Nonbonded nonbonded in nonbondeds) { if (nonbonded.types[0] == type0) { if (found != null) { bool writelog = ((found.epsilon != nonbonded.epsilon) || (found.Rmin2 != nonbonded.Rmin2) || (found.eps_14 != nonbonded.eps_14) || (found.Rmin2_14 != nonbonded.Rmin2_14)); if (writelog) { logger.Log(string.Format("Nonbonded params of {0}-(eps {1}, rmin2 {2}, esp_14 {3}, rmin2_14 {4}) is replaced to ({5}, {6}, {7}, {8})", type0, found.epsilon, found.Rmin2, found.eps_14, found.Rmin2_14, nonbonded.epsilon, nonbonded.Rmin2, nonbonded.eps_14, nonbonded.Rmin2_14)); } } found = nonbonded; } } HDebug.Assert(found != null); HDebug.AssertIf(double.IsNaN(found.Rmin2) == false, found.Rmin2 > 0); HDebug.AssertIf(double.IsNaN(found.Rmin2_14) == false, found.Rmin2_14 > 0); _FindNonbonded.Add(type0, found); } return(_FindNonbonded[type0]); }
public void RemoveHydrogens(ITextLogger logger) { foreach (Atom atom in new List <Atom>(atoms.ToArray())) { if (atom.IsHydrogen() == false) { continue; } if (atom.Bonds.Count != 1) { logger.Log("warning in removing hydrogen: {" + atom + "} has '!=1' number of bonded atom(s)"); } // isolate the atom, and remove it Atom bonded; { List <Atom> bondeds = new List <Atom>(atom.Bonds[0].atoms); bondeds.Remove(atom); HDebug.Assert(bondeds.Count == 1); bonded = bondeds[0]; } atom.Isolate(this); // assign its partial charge and mass to its bonded heavy atom bonded.Charge += atom.Charge; bonded.Mass += atom.Mass; // atoms.Remove(atom); } }
public static Universe Build(string pdbpath, string toppath, ITextLogger logger) { Pdb pdb = Pdb.FromFile(pdbpath); Top top = Top.FromFile(toppath); return(Build(pdb, top, logger)); }
public static Bond FromString(string line, ITextLogger logger) { Element elem = Element.FromString(line, 2, 2); double Kb = elem.parms[0]; double b0 = elem.parms[1]; Bond bond = new Bond(line, elem.types, Kb, b0); return(bond); }
public static Dihedral FromString(string line, ITextLogger logger) { Element elem = Element.FromString(line, 4, 3); double Kchi = elem.parms[0]; double n = elem.parms[1]; double delta = elem.parms[2] * Math.PI / 180.0; Dihedral dihedral = new Dihedral(line, elem.types, Kchi, n, delta); return(dihedral); }
public static Angle FromString(string line, ITextLogger logger) { Element elem = Element.FromString(line, 3, 4); double Ktheta = elem.parms[0]; double Theta0 = elem.parms[1] * Math.PI / 180.0; double Kub = (elem.parms.Length > 2) ? elem.parms[2] : 0; // double.NaN; double S0 = (elem.parms.Length > 3) ? elem.parms[3] : 0; // double.NaN; Angle angle = new Angle(line, elem.types, Ktheta, Theta0, Kub, S0); return(angle); }
public static Universe Build(IList <Tuple <Pdb, Namd.Psf> > lstPdbPsf, Namd.Prm prm, bool?ignore_neg_occupancy, IList <List <string> > lstLogger) { ITextLogger[] llstLogger = new ITextLogger[lstLogger.Count]; for (int i = 0; i < lstLogger.Count; i++) { llstLogger[i] = new TextLogger(lstLogger[i]); } var univ = Build(lstPdbPsf, prm, ignore_neg_occupancy, llstLogger); return(univ); }
public static Prm FromFileXPlor(string filepath, ITextLogger logger) { List <string> lines = new List <string>(System.IO.File.ReadAllLines(filepath)); RemoveComments(ref lines); string[] keywards = CollectKeywards(lines); List <Bond> bonds = new List <Bond>(); List <Angle> angles = new List <Angle>(); List <Dihedral> dihedrals = new List <Dihedral>(); List <Improper> impropers = new List <Improper>(); List <Nonbonded> nonbondeds = new List <Nonbonded>(); for (int i = 0; i < lines.Count; i++) { string line = lines[i]; string keyward = line.Split(separator, StringSplitOptions.RemoveEmptyEntries).First().ToUpper(); line = line.Substring(keyward.Length); switch (keyward) { case "REMARK": break; case "SET": break; case "BOND": bonds.Add(Bond.FromString(line, logger)); break; case "ANGLE": angles.Add(Angle.FromString(line, logger)); break; case "DIHE": dihedrals.Add(Dihedral.FromString(line, logger)); break; case "IMPR": impropers.Add(Improper.FromString(line, logger)); break; case "{*": break; // comment case "NONBONDED": nonbondeds.Add(Nonbonded.FromStringXPlor(line, logger)); break; default: HDebug.Assert(false); break; } } Prm prm = new Prm(); prm.bonds = bonds.ToArray(); prm.angles = angles.ToArray(); prm.dihedrals = dihedrals.ToArray(); prm.impropers = impropers.ToArray(); prm.nonbondeds = nonbondeds.ToArray(); return(prm); }
public static Improper FromString(string line, ITextLogger logger) { Element elem = Element.FromString(line, 4, 3); double Kpsi = elem.parms[0]; //Debug.Assert(elem.parms[1] == 0); if (!(elem.parms[1] == 0)) { logger.Log(string.Format("Warning: Improper params ({0}): first parameter should be '== 0' in general", line)); } double psi0 = elem.parms[2] * Math.PI / 180.0; Improper improper = new Improper(line, elem.types, Kpsi, psi0); return(improper); }
public static Prm FromLinesXXX(IList <string> lines, ITextLogger logger) { List <string> llines = new List <string>(lines); string[] header = FromFileXXX_CollectHeader(ref llines); //RemoveComments(ref lines); List <List <string> > liness = FromFileXXX_Regroup(ref llines); Prm prm = new Prm(); prm.bonds = FromFileXXX_CollectBonds(FromFileXXX_SelectLines(liness, "BONDS"), logger); prm.angles = FromFileXXX_CollectAngles(FromFileXXX_SelectLines(liness, "ANGLES"), logger); prm.dihedrals = FromFileXXX_CollectDihedrals(FromFileXXX_SelectLines(liness, "DIHEDRALS"), logger); prm.impropers = FromFileXXX_CollectImpropers(FromFileXXX_SelectLines(liness, "IMPROPER"), logger); prm.nonbondeds = FromFileXXX_CollectNonbondeds(FromFileXXX_SelectLines(liness, "NONBONDED"), logger); return(prm); }
public static Bond[] FromFileXXX_CollectBonds(List <string> lines, ITextLogger logger) { RemoveComments(ref lines); HDebug.Assert(lines[0].ToUpper() == "BONDS"); List <Bond> bonds = new List <Bond>(); foreach (string line in lines) { if (line.ToUpper() == "BONDS") { continue; } bonds.Add(Bond.FromString(line, logger)); } return(bonds.ToArray()); }
public static Angle[] FromFileXXX_CollectAngles(List <string> lines, ITextLogger logger) { RemoveComments(ref lines); HDebug.Assert(lines[0].ToUpper() == "ANGLES"); List <Angle> angles = new List <Angle>(); foreach (string line in lines) { if (line.ToUpper() == "ANGLES") { continue; } angles.Add(Angle.FromString(line, logger)); } return(angles.ToArray()); }
public static Nonbonded FromStringXPlor(string line, ITextLogger logger) { Element elem = Element.FromString(line, 1, 4); double epsilon = elem.parms[0]; double Rmin2 = elem.parms[1]; //Debug.Assert(Rmin2 > 0); if (!(Rmin2 > 0)) { logger.Log(string.Format("Error : Nonbonded params ({0}): 3rd parameter (Rmin2) must be '> 0'", line)); } double eps_14 = elem.parms[2]; double Rmin2_14 = elem.parms[3]; //Debug.Assert(Rmin2_14 > 0); if (!(Rmin2_14 > 0)) { logger.Log(string.Format("Error : Nonbonded params ({0}): 4th parameter (Rmin2_14) must be '> 0'", line)); } Nonbonded nonbonded = new Nonbonded(line, elem.types, epsilon, Rmin2, eps_14, Rmin2_14); return(nonbonded); }
public Angle FindAngle(string type0, string type1, string type2, ITextLogger logger) { string key = type0 + "-" + type1 + "-" + type2; if (_FindAngle.ContainsKey(key) == false) { Angle found = null; int found_count_X = int.MaxValue; foreach (Angle angle in angles) { int count_X = FindType(angle.types, type0, type1, type2); if (count_X == -1) { continue; } if (count_X < found_count_X) { found = angle; found_count_X = count_X; } else { bool writelog = ((count_X != found_count_X) || (found.Ktheta != angle.Ktheta) || (found.Theta0 != angle.Theta0) || (found.Kub != angle.Kub) || (found.S0 != angle.S0)); if (writelog) { logger.Log(string.Format("Angle params of {0}-{1}-{2}-(Ktheta {3}, Theta0 {4}, Kub {5}, S0 {6}) is replaced to ({7}, {8}, {9}, {10})", type0, type1, type2, found.Ktheta, found.Theta0, found.Kub, found.S0, angle.Ktheta, angle.Theta0, angle.Kub, angle.S0)); } } } HDebug.Assert(found != null); _FindAngle.Add(key, found); } return(_FindAngle[key]); }
protected PeriodicalObserver( ITextLogger textLogger = null, int dueTime = 0, int periodMilliseconds = 1000) { this.textLogger = textLogger; this.dueTime = dueTime; this.periodMilliseconds = periodMilliseconds; this.ObeservedEvent = new ReferenceCountableEventContainer <T>( handler => this.Observed += handler, handler => this.Observed -= handler); this.timer = CreateTimer(); this.DisposeActions.Add(() => { this?.timer.Dispose(); }); this.DisposeActions.Add( this.ObeservedEvent.NotifyCollectionChanged.Subscribe( OnObserveEventCollectionChanged)); }
public Bond FindBond(string type0, string type1, ITextLogger logger) { string key = type0 + "-" + type1; if (_FindBond.ContainsKey(key) == false) { Bond found = null; int found_count_X = int.MaxValue; foreach (Bond bond in bonds) { int count_X = FindType(bond.types, type0, type1); if (count_X == -1) { continue; } if (count_X < found_count_X) { found = bond; found_count_X = count_X; } else { bool writelog = ((count_X != found_count_X) || (found.Kb != bond.Kb) || (found.b0 != bond.b0)); if (writelog) { logger.Log(string.Format("Bond params of {0}-{1}-(Kb {2}, b0 {3}) is replaced to ({4}, {5})", type0, type1, found.Kb, found.b0, bond.Kb, bond.b0)); } } } HDebug.Assert(found != null); _FindBond.Add(key, found); } return(_FindBond[key]); }
public void RemoveTextLogger(ITextLogger logger) { lock (_autoFlushSync) { // pause auto flush while removing a logger _textLoggers.Remove(logger); } }
public static Nonbonded[] FromFileXXX_CollectNonbondeds(List <string> lines, ITextLogger logger) { RemoveComments(ref lines); HDebug.Assert(lines[0].Split(separator).First().ToUpper() == "NONBONDED"); List <Nonbonded> nonbondeds = new List <Nonbonded>(); bool skip = false; foreach (string line in lines) { if (line.Split(separator).First().ToUpper() == "NONBONDED") { skip = true; continue; } if (skip) { skip = false; continue; } nonbondeds.Add(Nonbonded.FromString(line, logger)); } return(nonbondeds.ToArray()); }
public TextLogComposer(ITextLogger logger) { this.logger = logger; this.ScriptLogger = new RuleLogger(this); }
public static Universe Build(Pdb pdb, Gromacs.Top top, ITextLogger logger) { return(BuilderGromacs.Build(pdb, top, logger)); }
public void AddTextLogger(ITextLogger logger) { _textLoggers.Add(logger); }
public void RemoveTextLogger(ITextLogger logger) { _textLoggers.Remove(logger); }
public static ITextLogger Resolve(this ITextLogger textLogger) { return(textLogger ?? new DefaultTextLogger()); }
public static Universe Build(Pdb pdb, Gromacs.Top top, ITextLogger logger) { Universe univ = new Universe(); // atoms List <Top.Atom> top_atoms = top.elements.SelectSourceExtTop().ListAtom().SelectMatchToPdb(pdb.atoms); List <Top.Bond> top_bonds = top.elements.SelectSourceExtTop().ListType <Top.Bond>(); List <Top.Pair> top_pairs = top.elements.SelectSourceExtTop().ListType <Top.Pair>(); ///Debug.ToDo("handle pairtype <= nbnd 1-4"); List <Top.Angle> top_angles = top.elements.SelectSourceExtTop().ListType <Top.Angle>(); List <Top.Dihedral> top_dihedral = top.elements.SelectSourceExtTop().ListType <Top.Dihedral>(); List <Top.Atomtypes> top_atomtypes = top.elements.ListAtomtypes(); List <Top.Bondtypes> top_bondtypes = top.elements.ListType <Top.Bondtypes>(); List <Top.Angletypes> top_angletypes = top.elements.ListType <Top.Angletypes>(); List <Top.Dihedraltypes> top_dihedraltypes = top.elements.ListType <Top.Dihedraltypes>(); List <Top.Pairtypes> top_pairtypes = top.elements.ListType <Top.Pairtypes>(); ///Debug.ToDo("handle pairtype <= nbnd 1-4"); { ///Debug.ToDo("handle here"); List <Top.LineElement> elems = new List <Top.LineElement>(top.elements); foreach (var elem in top_atoms) { HDebug.Verify(elems.Remove(elem)); } foreach (var elem in top_bonds) { HDebug.Verify(elems.Remove(elem)); } foreach (var elem in top_pairs) { HDebug.Verify(elems.Remove(elem)); } foreach (var elem in top_angles) { HDebug.Verify(elems.Remove(elem)); } foreach (var elem in top_dihedral) { HDebug.Verify(elems.Remove(elem)); } foreach (var elem in top_atomtypes) { HDebug.Verify(elems.Remove(elem)); } foreach (var elem in top_bondtypes) { HDebug.Verify(elems.Remove(elem)); } foreach (var elem in top_angletypes) { HDebug.Verify(elems.Remove(elem)); } foreach (var elem in top_dihedraltypes) { HDebug.Verify(elems.Remove(elem)); } foreach (var elem in top_pairtypes) { HDebug.Verify(elems.Remove(elem)); } List <Top.LineElement> srcitp = new List <Top.LineElement>(); List <Top.LineElement> srctop = new List <Top.LineElement>(); for (int i = 0; i < elems.Count; i++) { if ((elems[i].source as string).EndsWith(".itp")) { srcitp.Add(elems[i]); elems[i] = null; continue; } if ((elems[i].source as string).EndsWith(".top")) { srctop.Add(elems[i]); elems[i] = null; continue; } } elems = elems.HRemoveAllNull().ToList(); HDebug.Assert(elems.Count == 0); } Atoms atoms = new Atoms(univ); HDebug.Assert(pdb.atoms.Length == top_atoms.Count); for (int i = 0; i < top_atoms.Count; i++) { //Debug.Assert(psf.atoms[i].AtomId == pdb.atoms[i].serial); //string type0 = psf.atoms[i].AtomType; //Atom atom = new Atom(psf.atoms[i], prm.FindNonbonded(type0, logger), pdb.atoms[i]); //atom.Coord = pdb.atoms[i].coord; //atoms.Add(atom); Gromacs.Top.Atom atom = top_atoms[i]; HDebug.Assert(i + 1 == atom.cgnr); HDebug.Assert(atom.cgnr == pdb.atoms[i].serial); //Gromacs.Top.Atomtypes atomtype = top_atomtypes[atom.type]; List <Gromacs.Top.Atomtypes> atomtypes = FindTypes(top_atomtypes, atom.type); HDebug.Assert(atomtypes.Count == 1); Gromacs.Top.Atomtypes atomtype = atomtypes.Last(); //Debug.Assert(atom.charge == atomtype.charge); //Debug.Assert(atom.mass == atomtype.mass ); Atom uatom = new Atom(atom.cgnr, atom.atom, atom.type, pdb.atoms[i].element.Trim() , atom.resnr, atom.residu , atom.charge, atom.mass , atomtype.epsilon, atomtype.sigma , double.NaN, double.NaN , atom, atomtype ); uatom.Coord = pdb.atoms[i].coord; atoms.Add(uatom); } // bonds Bonds bonds = new Bonds(); for (int i = 0; i < top_bonds.Count; i++) { int idx0 = top_bonds[i].ai - 1; Atom atom0 = atoms[idx0]; string type0 = atom0.AtomType; int idx1 = top_bonds[i].aj - 1; Atom atom1 = atoms[idx1]; string type1 = atom1.AtomType; List <Gromacs.Top.Bondtypes> bondtypes = FindTypes(top_bondtypes, type0, type1); //Debug.Assert(bondtypes.Count == 1); Gromacs.Top.Bondtypes bondtype = bondtypes.Last(); //Gromacs.Top.Bondtypes bondtype = top_bondtypes[Gromacs.Top.Bondtypes.GetStringKey(type0,type1)]; Bond bond = new Bond(atom0, atom1, bondtype.kb, bondtype.b0, bondtype); bonds.Add(bond); atom0.Bonds.Add(bond); atom0.Inter123.Add(atom1); atom0.Inter12.Add(atom1); atom1.Bonds.Add(bond); atom1.Inter123.Add(atom0); atom1.Inter12.Add(atom0); } // angles Angles angles = new Angles(); for (int i = 0; i < top_angles.Count; i++) { int idx0 = top_angles[i].ai - 1; Atom atom0 = atoms[idx0]; string type0 = atom0.AtomType; int idx1 = top_angles[i].aj - 1; Atom atom1 = atoms[idx1]; string type1 = atom1.AtomType; int idx2 = top_angles[i].ak - 1; Atom atom2 = atoms[idx2]; string type2 = atom2.AtomType; List <Gromacs.Top.Angletypes> angletypes = FindTypes(top_angletypes, type0, type1, type2); //Debug.Assert(angletypes.Count == 1); Gromacs.Top.Angletypes angletype = angletypes.Last(); //Gromacs.Top.Angletypes angletype = top_angletypes[Gromacs.Top.Bondtypes.GetStringKey(type0, type1, type2)]; Angle angle = new Angle(atom0, atom1, atom2 , angletype.cth, angletype.th0, angletype.cub, angletype.ub0 , angletype ); angles.Add(angle); atom0.Angles.Add(angle); atom0.Inter123.Add(atom1); atom0.Inter123.Add(atom2); atom1.Angles.Add(angle); atom1.Inter123.Add(atom2); atom1.Inter123.Add(atom0); atom2.Angles.Add(angle); atom2.Inter123.Add(atom0); atom2.Inter123.Add(atom1); } // dihedrals Dihedrals dihedrals = new Dihedrals(); Impropers impropers = new Impropers(); for (int i = 0; i < top_dihedral.Count; i++) { int idx0 = top_dihedral[i].ai - 1; Atom atom0 = atoms[idx0]; string type0 = atom0.AtomType; int idx1 = top_dihedral[i].aj - 1; Atom atom1 = atoms[idx1]; string type1 = atom1.AtomType; int idx2 = top_dihedral[i].ak - 1; Atom atom2 = atoms[idx2]; string type2 = atom2.AtomType; int idx3 = top_dihedral[i].al - 1; Atom atom3 = atoms[idx3]; string type3 = atom3.AtomType; int funct = top_dihedral[i].funct; List <Gromacs.Top.Dihedraltypes> dihedraltypes = FindTypes(top_dihedraltypes, type0, type1, type2, type3); { List <Gromacs.Top.Dihedraltypes> ldihedraltypes = new List <Top.Dihedraltypes>(dihedraltypes); // select funct matching to its query for (int j = 0; j < ldihedraltypes.Count;) { if (ldihedraltypes[j].func == funct) { j++; } else { ldihedraltypes.RemoveAt(j); } } // if there are no matching query but improper, select the improper if ((ldihedraltypes.Count == 0) && (dihedraltypes[0].func == 2)) { ldihedraltypes.Add(dihedraltypes[0]); } dihedraltypes = new List <Top.Dihedraltypes>(ldihedraltypes); } //{ // // if dihedral(func==9) and improper(func==2) are mixed // // select only improper // bool has_func_2 = false; // for(int j=0; j<dihedraltypes.Count; j++) // if(dihedraltypes[j].func == 2) // has_func_2 = true; // if(has_func_2) // { // for(int j=0; j<dihedraltypes.Count; ) // { // if(dihedraltypes[j].func == 2) // j++; // else // dihedraltypes.RemoveAt(j); // } // } //} if (dihedraltypes[0].func == 9) { // dihedral for (int j = 1; j < dihedraltypes.Count; j++) { HDebug.Assert(dihedraltypes[0].func == dihedraltypes[j].func); HDebug.Assert(dihedraltypes[0].i.Trim() == dihedraltypes[j].i.Trim()); HDebug.Assert(dihedraltypes[0].j.Trim() == dihedraltypes[j].j.Trim()); HDebug.Assert(dihedraltypes[0].k.Trim() == dihedraltypes[j].k.Trim()); HDebug.Assert(dihedraltypes[0].l.Trim() == dihedraltypes[j].l.Trim()); } Gromacs.Top.Dihedraltypes dihedraltype = dihedraltypes.Last(); Dihedral dihedral = new Dihedral(atom0, atom1, atom2, atom3 , dihedraltype.cp, dihedraltype.mult, dihedraltype.phi0 , dihedraltype ); dihedrals.Add(dihedral); atom0.Dihedrals.Add(dihedral); //atom0.Inter123.Add(atom1); atom0.Inter123.Add(atom2); atom0.Inter123.Add(atom3); atom1.Dihedrals.Add(dihedral); //atom1.Inter123.Add(atom2); atom1.Inter123.Add(atom3); atom1.Inter123.Add(atom0); atom2.Dihedrals.Add(dihedral); //atom2.Inter123.Add(atom3); atom2.Inter123.Add(atom0); atom2.Inter123.Add(atom1); atom3.Dihedrals.Add(dihedral); //atom3.Inter123.Add(atom0); atom3.Inter123.Add(atom1); atom3.Inter123.Add(atom2); continue; } if (dihedraltypes[0].func == 2) { // improper for (int j = 1; j < dihedraltypes.Count; j++) { HDebug.Assert(dihedraltypes[0].func == dihedraltypes[j].func); HDebug.Assert(dihedraltypes[0].i.Trim() == dihedraltypes[j].i.Trim()); HDebug.Assert(dihedraltypes[0].j.Trim() == dihedraltypes[j].j.Trim()); HDebug.Assert(dihedraltypes[0].k.Trim() == dihedraltypes[j].k.Trim()); HDebug.Assert(dihedraltypes[0].l.Trim() == dihedraltypes[j].l.Trim()); } Gromacs.Top.Dihedraltypes impropertype = dihedraltypes.Last(); Improper improper = new Improper(atom0, atom1, atom2, atom3 , impropertype.cp, impropertype.phi0 , impropertype ); impropers.Add(improper); atom0.Impropers.Add(improper); //atom0.Inter123.Add(atom1); atom0.Inter123.Add(atom2); atom0.Inter123.Add(atom3); atom1.Impropers.Add(improper); //atom1.Inter123.Add(atom2); atom1.Inter123.Add(atom3); atom1.Inter123.Add(atom0); atom2.Impropers.Add(improper); //atom2.Inter123.Add(atom3); atom2.Inter123.Add(atom0); atom2.Inter123.Add(atom1); atom3.Impropers.Add(improper); //atom3.Inter123.Add(atom0); atom3.Inter123.Add(atom1); atom3.Inter123.Add(atom2); continue; } HDebug.Assert(false); //Debug.Assert(dihedraltypes.Count == 1); // //for(int j=0; j<dihedraltypes.Count; j++) // if(dihedraltypes[j].func != 2) // dihedraltype = dihedraltypes[j]; //Debug.Assert(dihedraltype != null); //List<Gromacs.Top.Dihedraltypes> dihedraltypes = top_dihedraltypes[Gromacs.Top.Dihedraltypes.GetStringKey(type0, type1, type2, type3)]; } // 1-4 interactions for (int i = 0; i < atoms.Count; i++) { HashSet <Atom> Inter14 = new HashSet <Atom>(); BuildInter1toN(atoms[i], 4, Inter14); // find all atoms for 1-4 interaction Inter14.Remove(atoms[i]); // remove self foreach (Atom atom in atoms[i].Inter123) { Inter14.Remove(atom); // remove all 1-2, 1-3 interactions } atoms[i].Inter14 = Inter14; } Nonbonded14s nonbonded14s = new Nonbonded14s(); nonbonded14s.Build(atoms); //// nonbondeds //// do not make this list in advance, because it depends on the atom positions //Nonbondeds nonbondeds = new Nonbondeds(); //nonbondeds.Build(atoms); //Universe univ = new Universe(); univ.pdb = pdb; univ.refs.Add("top", top); univ.atoms = atoms; univ.bonds = bonds; univ.angles = angles; univ.dihedrals = dihedrals; univ.impropers = impropers; //univ.nonbondeds = nonbondeds ; // do not make this list in advance, because it depends on the atom positions univ.nonbonded14s = nonbonded14s; HDebug.Assert(univ.Verify()); return(univ); }
public Dihedral[] FindDihedral(string type0, string type1, string type2, string type3, ITextLogger logger) { string key = type0 + "-" + type1 + "-" + type2 + "-" + type3; if (_FindDihedral.ContainsKey(key) == false) { Dictionary <double, Tuple <int, Dihedral> > found = new Dictionary <double, Tuple <int, Dihedral> >(); //int found_count_X = int.MaxValue; foreach (Dihedral dihedral in dihedrals) { int count_X = FindType(dihedral.types, type0, type1, type2, type3); if (count_X == -1) { continue; } /// http://www.charmm.org/documentation/c32b2/parmfile.html // assign garbage dihedral if (found.ContainsKey(dihedral.n) == false) { found.Add(dihedral.n, new Tuple <int, Dihedral>(int.MaxValue, null)); } // if current "count of wildcards (X)" is smaller than alreayd assigned, replace existing one if (count_X < found[dihedral.n].Item1) { found[dihedral.n] = new Tuple <int, Dihedral>(count_X, dihedral); } #region commented-out old code //if(count_X < found_count_X) //{ // found = dihedral; // found_count_X = count_X; //} //else //{ // bool writelog = ((count_X != found_count_X ) || // (found.Kchi != dihedral.Kchi ) || // (found.n != dihedral.n ) || // (found.delta != dihedral.delta)); // if(writelog && (logger!=null)) // { // logger.Log(string.Format("Dihedral params of {0}-{1}-{2}-{3}-(Kchi {4}, n {5}, delta {6:G4}) is replaced to ({7}, {8}, {9:G4})", // type0, type1, type2, type3, found.Kchi, found.n, found.delta, // dihedral.Kchi, dihedral.n, dihedral.delta)); // } //} #endregion } HDebug.Assert(found.Count != 0); _FindDihedral.Add(key, found.Values.ToArray().HListItem2()); } return(_FindDihedral[key]); }
protected ClassObserverBase(ITextLogger textLogger = null) : base(textLogger) { }