50 #define NAME_CHAR_COUNT 128 56 bool mol2_start =
false;
59 if ( strstr(line.c_str(),
"@<TRIPOS>MOLECULE") )
73 while(text_stream.
readLine(line) && !strstr(line.c_str(),
"@<TRIPOS>ATOM")) { }
78 while(text_stream.
readLine(line) && !strstr(line.c_str(),
"@<TRIPOS>BOND"))
82 int tokens = sscanf(line.c_str(),
"%d %s %f %f %f %s", &id, atom_name, &pos.
x(), &pos.
y(), &pos.
z(), atom_type);
94 char* ch = strstr(atom_type,
".");
110 if ( strstr(line.c_str(),
"@<TRIPOS>") )
116 int tokens = sscanf(line.c_str(),
"%d %d %d %s", &id, &bond_atom1, &bond_atom2, bond_type);
123 if ( !(bond_atom1 < structure->atoms().size() && bond_atom2 < structure->atoms().size()) )
125 Log::error(
Say(
"Bond indices out of range: a1 = %n, a2 = %n, atom count = %n.\n") << bond_atom1 << bond_atom2 << structure->
atoms().size() );
128 VL_CHECK( bond_atom1 < structure->atoms().size() )
129 VL_CHECK( bond_atom2 < structure->atoms().size() )
131 bond->setAtom1( structure->atom(bond_atom1) );
132 bond->setAtom2( structure->atom(bond_atom2) );
134 if (bond_type[0] == '1') bond->setBondType(
BT_Single );
135 if (bond_type[0] == '2') bond->setBondType(
BT_Double );
136 if (bond_type[0] == '3') bond->setBondType(
BT_Triple );
137 if (strstr(bond_type, "ar")) bond->setBondType(
BT_Aromatic );
138 if (strstr(bond_type, "am")) bond->setBondType(
BT_Amide );
139 if (strstr(bond_type, "du")) bond->setBondType(
BT_Dummy );
140 if (strstr(bond_type, "un")) bond->setBondType(
BT_Unknown );
141 if (bond->bondType() == BT_Aromatic)
144 bond->setColor(
fvec4(0,1.0f,0,1.0f));
147 bond->setUseAtomColors(
true);
149 structure->
addBond( bond.get() );
163 ring_extractor.
run();
190 bool is_mol2 =
false;
193 const char* pos = strstr(line.c_str(),
"@<TRIPOS>MOLECULE");
194 if ( pos && line == pos )
210 while( (structure = parseStructure(text_stream) ) )
212 if (structure->
atoms().size())
214 structures.push_back(structure);
215 structure->
tags()->
set(
"MultiMol2Index") =
Say(
"%n") << structures.size() - 1;
216 structure->
tags()->
set(
"FilePath") = vfile->
path();
The Molecule class is used to manage and render 3D molecular structures.
void setAtomName(const std::string &name)
An abstract class representing a file.
bool readLine(std::string &utf8)
Vector4< float > fvec4
A 4 components vector with float precision.
void setCoordinates(const fvec3 &coordinates)
A simple String formatting class.
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
const T_Scalar & z() const
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
const std::vector< ref< Atom > > & atoms() const
void setInputFile(VirtualFile *file)
virtual void close()=0
Closes the file.
const String & path() const
Returns the path of the file.
void setMoleculeName(const String &name)
Visualization Library main namespace.
void setUseAtomColors(bool use_atom_color)
The TextStream class can be used to conveniently read or parse utf8-encoded text files.
A VirtualFile to manipulate files stored in memory.
EAtomType atomType(const char *type)
Translates a string containing atom type name, atom symbol or a Sybyl type into an EAtomType...
const T_Scalar & y() const
void setCovalentAtomRadii(float percentage=1.0f)
Sets all the atoms' radii to their covalent atom radii.
virtual bool open(EOpenMode mode)
Opens the file in the specified mode.
void setAtomType(EAtomType type)
VLCORE_EXPORT ref< VirtualFile > locateFile(const String &path)
Utility function, equivalent to vl::defFileSystem()->locateFile(path)
static std::string trimStdString(const std::string &text)
Remove the spaces before and after an std::string.
void computeAtomAdjacency()
void setCPKAtomColors()
Sets all the atoms' color to their CPK color.
const T_Scalar & x() const
The Bond class represents a bond to be used with the Molecule class.
void ungetLine(const std::string &utf8)
The ref<> class is used to reference-count an Object.
The Atom class represents an atom to be used with the Molecule class.
String & set(const String &key)
VLMOLECULE_EXPORT bool loadMOL2(const String &path, std::vector< ref< Molecule > > &structures)
Loads a Tripos MOL2 file.
void copy(VirtualFile *file)
Copies the data of any kind of VirtualFile.