The timing of the atomic bombings of Japan were definitely influenced by a hope that they might be able to get Japan to surrender before the Soviet Union declared war on Japan. If that happened, then the Soviets would not get certain territorial concessions that they had been promised, and it would also forestall the difficulties that would come when the Soviets liberated a country from Axis powers (and then left pro-Soviet figures in charge), which the US had began to reckon with after seeing what had happened to Poland.
It was not a case that they thought that the Soviet Union had a very high chance of occupying Japan in any meaningful way. (As it turned out, Stalin was very intrigued by conducting operations against Hokkaido, the northernmost island, but was talked out of it by Molotov.) If the atomic bombs did not produce an immediate capitulation, they did think that the Soviet declaration of war would likely do it. So they weren't completely against the Soviets being involved; if the bombs didn't "work" they definitely wanted the Soviets involved. But they hoped that maybe the bomb would make the Soviet situation moot.
In terms of the timing, at the Potsdam Conference (July 1945), the schedule of the bombings was worked out. Truman wanted the first atomic bomb (and Truman put all of his thought on the "first" one, which he may have thought was the "only" one — his knowledge of these things was somewhat muddled) dropped as soon as the Potsdam Conference ended (after August 3rd). He had the impression that the Soviets could not invade until mid-August. So he had a limited window to work with on this.
As it turned out, weather delayed the bombing of Hiroshima until August 6th. Stalin accelerated his plans on the Eastern Front and moved up the invasion to August 9th (from August 15th or so), hoping to get in on the war before it ended. So they were both "racing" in a way. This is why Tsuyoshi Hasegawa calls his book on the subject of the Soviet–Japanese-US relations at the end of World War II Racing the Enemy. (For more information on these events, see the book.)
All that aside, I would just clarify that this was a motivation for Truman (et al.), notably for the timing. But it was not the motivation nor really a primary motivation. It was an extra possible benefit to be gained from the atomic bomb. It was not the only reason it was dropped (they had many reasons to want to drop it, and almost no reasons not to).